Qt 中 QDialog 的问题
我正在使用 Qt for Symbian。我从 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::TestDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect rect = desktopWidget->availableGeometry();
this->setFixedWidth(rect.width());
}
I'm using Qt for Symbian. I have some problems with a QDialog that I open from a QMenu. The QDialog shows up fine and in the QDialog I have a QDialogButtonBox with a button to Close the QDialog. BUT if I close the QDialog and then open it from the QMenu again, it will show up but the button from the QDialogButtonBox will not show up. Instead the buttons from the QMainWindow will show but they are grayed out.
How can I get the QDialog buttons to show every time? Maybe I have some problems with setting focus on the QDialog? I really can't see what I'm doing wrong here.
It's not much code that I use, you can try it yourself. This is my code:
In QMainWindow I use the following to create the menu:
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);
This shows the QDialog:
void MyMainWindow::showPopup(){
TestDialog *test = new TestDialog(this);
test->setAttribute(Qt::WA_DeleteOnClose);
test->show();
}
This is the TestDialog:
TestDialog::TestDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect rect = desktopWidget->availableGeometry();
this->setFixedWidth(rect.width());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望对话框是模态的,请使用 exec()。否则,您应该使用 show() 和 raise() 来确保它位于顶部。
If you want your dialog to be modal, use exec(). Otherwise, you should use show() and raise() to make sur it's on top.