开发者

Problems with QDialog in Qt

开发者 https://www.devze.com 2022-12-27 17:25 出处:网络
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

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());
}


If you want your dialog to be modal, use exec(). Otherwise, you should use show() and raise() to make sur it's on top.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号