QMenu *fileMenu = new QMenu(tr("&File"),this); QAction *newAction = new QAction(tr("&New"),this); fileMenu->addAction(newAction); QMenuBar *menuBar = new QMenuBar(this); menuBar->addMenu(fileMenu); connect(newAction,SIGNAL(triggered()),this,SLOT(fileNew()));为什么创建出来的菜单那么丑?菜单栏 file 右边有一块空白区域,上面没有任何显示。
QMenu *fileMenu = new QMenu(tr("&File"),this); QMenu *editMenu = new QMenu(tr("&Edit"),this); QAction *newAction = new QAction(tr("&New"),this); QAction *copyAction = new QAction(tr("&Copy"),this); fileMenu->addAction(newAction); editMenu->addAction(copyAction); QMenuBar *menuBar = new QMenuBar(this); menuBar->addMenu(fileMenu); menuBar->addMenu(editMenu); connect(newAction,SIGNAL(triggered()),this,SLOT(fileNew())); connect(copyAction,SIGNAL(triggered()),this,SLOT(editCopy()));增加一项 Edit 菜单后,创建的菜单栏与1的宽度是相同的,Edit 菜单项正好占用了1中的空白区域。
QMenu *fileMenu = new QMenu(tr("&File"),this); QMenu *editMenu = new QMenu(tr("&Edit"),this); QMenu *helpMenu = new QMenu(tr("&Help"),this); QAction *newAction = new QAction(tr("&New"),this); QAction *copyAction = new QAction(tr("&Copy"),this); QAction *aboutAction = new QAction(tr("&About"),this); fileMenu->addAction(newAction); editMenu->addAction(copyAction); helpMenu->addAction(aboutAction); QMenuBar *menuBar = new QMenuBar(this); menuBar->addMenu(fileMenu); menuBar->addMenu(editMenu); menuBar->addMenu(helpMenu); connect(newAction,SIGNAL(triggered()),this,SLOT(fileNew())); connect(copyAction,SIGNAL(triggered()),this,SLOT(editCopy())); connect(aboutAction,SIGNAL(triggered()),this,SLOT(helpAbout()));再增加一个 Help 菜单时,发现显示与1相似,菜单项有一空白、只是多了一个指示,类似于 >>; 点击后才显示出 Edit 和 Help。
怎么才能设定菜单栏的宽度,以避免出现1和3的问题?
继续学习中,希望可以解决上述问题。