我正在为 Symbian 使用 Qt。我从 QMenu 打开的 QDialog 有一些问题。QDialog 显示得很好,在 QDialog 中我有一个 QDialogButtonBox,带有一个关闭 QDialog 的按钮。但是如果我关闭 QDialog 然后再次从 QMenu 打开它,它会显示出来,但 QDialogButtonBox 中的按钮不会显示。相反,来自 QMainWindow 的按钮将显示,但它们是灰色的。
如何让 QDialog 按钮每次都显示?也许我在将焦点放在 QDialog 上时遇到了一些问题?我真的看不出我在这里做错了什么。
我用的代码不多,大家可以自己试试。这是我的代码:
在 QMainWindow 我使用以下内容来创建菜单:
QAction *menuButton = new QAction("Menu", this);
menuButton->setSoftKeyRole(QAction::PositiveSoftKey);
QMenu *menu = new QMenu(this);
menuButton->setMenu(menu);
QAction *popup = new QAction("Show popup",this);
connect(popup, SIGNAL(triggered()), this, SLOT(showPopup()));
menu->addAction(popup);
addAction(menuButton);
这显示了 QDialog:
void MyMainWindow::showPopup(){
TestDialog *test = new TestDialog(this);
test->setAttribute(Qt::WA_DeleteOnClose);
test->show();
}
这是测试对话框:
TestDialog::TestDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect rect = desktopWidget->availableGeometry();
this->setFixedWidth(rect.width());
}