[英]open new window as a dialog (Qt4)
I created a main window and new window.我创建了一个主窗口和新窗口。 when a button is pressed on the main window the new window will appear.当按下主窗口上的按钮时,将出现新窗口。 thats all right.没关系。 but I need the new window to apper as a dialog.但我需要新窗口作为对话框。 that means whan a dialog is opened the main window will not function untill the dialog is closed.这意味着打开对话框后,主窗口将无法运行,直到对话框关闭。 and when a dialog is opened a new tsb will not apper in the taskbar.并且当打开对话框时,新的 tsb 将不会出现在任务栏中。 how to do this.这该怎么做。
here are some codes what i used,这是我使用的一些代码,
mainwindow.h主窗口.h
private:
Form *myform;
public slots:
void myformshow();
mainwindow.cpp主窗口.cpp
mainWin::mainWin(QWidget *parent)
{
setupUi(this);
connect(pushButton,SIGNAL(clicked()),this,SLOT(myformshow()));
}
void mainWin::myformshow(){
myform= new Form(); //make sure to delete newform someware.
myform->show();
}
form.h表格.h
class Form : public QWidget, private Ui::Form
{
Q_OBJECT
public:
Form(QWidget *parent);
public slots:
void command();
};
#endif // FORM_H
here Form means, I created the new window as forms.h
and its class is Form
这里 Form 的意思是,我创建了一个名为forms.h
的新窗口,它的类是Form
Make the second window inherit from QDialog (not strictly necessary, but will give you correct platform-specific behavior, like centering and various window flags), set the main window as its parent, and run it using its exec()
function.使第二个窗口从 QDialog 继承(不是绝对必要的,但会为您提供正确的特定于平台的行为,例如居中和各种窗口标志),将主窗口设置为其父窗口,并使用其exec()
函数运行它。
First, change your Form class to inherit from QDialog:首先,将您的 Form 类更改为从 QDialog 继承:
class Form : public QDialog, private Ui::Form
(If you had references to QWidget elsewhere in your From class code, change them too.) (如果您在 From 类代码的其他地方引用了 QWidget,也请更改它们。)
Then, in your mainWin::myformshow() function, do:然后,在您的 mainWin::myformshow() 函数中,执行以下操作:
void mainWin::myformshow()
{
myform = new Form; //make sure to delete newform someware.
myform->exec();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.