QWidget * MyAction::createWidget(QWidget * parent)
{
if (parent->inherits("QMenu") || parent->inherits("QToolBar")) {
QSplitter * splitter = new QSplitter(parent);
QLabel * label = new QLabel;
label->setText(tr("insert text: "));
splitter->addWidget(label);
splitter->addWidget(lineEdit);
return splitter;
}
return 0;
}
函数定义如上,在调用MyAction时:
MyAction * action = new MyAction;
ui->mainToolBar->addAction(action);
然而如果这样调用:
MyAction * action = new MyAction;
QMenu * editMenu = ui->menuBar->addMenu("edit(&E)");
editMenu->addAction(action);
则生成的QSplitter无法显示
请问如何能够在菜单栏而不是工具栏中正常使用?
例子来自Qt creator快速入门第五章