在下面的代码中,我创建Qt Widget的Application,基类QMainWindow,并且没有.ui形式。不能理解为什么MenuBar不显示,尝试了不同的变体并且没有人可用。
此图像演示了我得到的
。
系统Ubuntu 16.04。使用QMake 3.0版和Qt 5.5.1版
注意:在其他计算机上,相同的代码也可以正常工作。
在mainwindow.h下面
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
#include <QWidget>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QMenu *file;
};
#endif // MAINWINDOW_H
在mainwindow.cpp下面,带有注释的行显示了我如何尝试对其进行修复。
#include "mainwindow.h"
#include <QtGui>
#include <QtWidgets>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//QVBoxLayout *vbl = new QVBoxLayout;
QMenu *file = new QMenu("&File"); //menuBar()->addMenu("&File");//new QMenu("&File");
file->addAction("&Quit",qApp,SLOT(quit()),Qt::CTRL+Qt::Key_Q);
QMenuBar *mb = menuBar();
mb->addMenu(file);
mb->show();
setMenuBar(mb);
//vbl->setMenuBar(mb);
//setLayout(vbl);
resize(400,400);
}
MainWindow::~MainWindow()
{
}
After some investigations and reinstalling of all components I solved this simple problem. Need to change in 'System Settings -> Appearance -> Behavior' parameter for 'Show the menus for a window' from the "In the menu bar" to "In the window's title bar". Thanks to everyone who tried to help.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句