2014-09-29 84 views
1

我想设置此QT UI为“模式少”,我试过setModal(false),但不幸的是它不起作用。意义:它编译和运行,但我仍然不能让孩子的UI和父母并行工作。我正在使用QT 4.8。在Visual Studio 2010中这里是我的代码:qt setmodal无法正常工作

realtimedlg::realtimedlg(QWidget *parent) 
{ 
    ui.setupUi(this); 
    parentWnd = parent; 
    init(); 
    timer1.start(100, this); 
    this->setModal(false); // this does not do anything! 
} 

回答

2

你并不需要调用setModal(false)可言,因为false是默认值了。

正如Qt的docs说:

本属性是否显示()应该弹出的对话框中,模式 或无模式。

默认情况下,此属性为false,show()弹出对话框为 非模态。将他的属性设置为true相当于将QWidget :: windowModality设置为Qt :: ApplicationModal,即 。

exec()忽略此属性的值,并始终弹出 对话框为模态。

所以,当你实例化对象realtimedlg你应该从堆做到这一点,只需要调用show()方法:

realtimedlg* dlg = new realtimedlg(this); 
dlg->show(); 

你并不需要调用exec()。调用它会使你的对话模式。

+0

我做到了,但我的realtimedlg显示很短的时间,然后消失! – Samer 2014-09-29 19:40:08

+0

这是因为你在堆栈上创建它,你应该从堆中创建。 – 2014-09-29 19:41:28

+0

@Samer,请检查最新的答案。 – 2014-09-29 19:46:40