Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使弹出窗口成为QT中的顶级窗口?_C++_Qt_User Interface - Fatal编程技术网

C++ 如何使弹出窗口成为QT中的顶级窗口?

C++ 如何使弹出窗口成为QT中的顶级窗口?,c++,qt,user-interface,C++,Qt,User Interface,在QT中,当单击按钮并弹出窗口时,用户仍然可以返回并单击相同的按钮(无限次)。如何使按钮弹出的窗口保持在其他窗口的顶部? 在这种情况下,弹出窗口的是“编辑”按钮 这是window.cpp #include "window.h" #include "editwindow.h" #include "ui_window.h" #include <QtGui/QApplication> #include <QtGui> Window::Window(QWidget *paren

在QT中,当单击按钮并弹出窗口时,用户仍然可以返回并单击相同的按钮(无限次)。如何使按钮弹出的窗口保持在其他窗口的顶部? 在这种情况下,弹出窗口的是“编辑”按钮

这是window.cpp

#include "window.h"
#include "editwindow.h"
#include "ui_window.h"
#include <QtGui/QApplication>
#include <QtGui>

Window::Window(QWidget *parent) :
QDialog(parent),
ui(new Ui::Window)
{
ui->setupUi(this);

ShowEdit = new QPushButton(tr("Edit"));
ShowEdit -> show();
connect(ShowEdit, SIGNAL(clicked()), this, SLOT(popup()));

Remove = new QPushButton(tr("Remove"));
Remove -> show();
connect(Remove, SIGNAL(clicked()), this, SLOT(ProgramRemove()));

OK = new QPushButton(tr("OK"));
OK -> show();
connect(OK, SIGNAL(clicked()), this, SLOT(Saved()));

Quit = new QPushButton(tr("Quit"));
Quit -> show();
connect(Quit, SIGNAL(clicked()), this, SLOT(close()));

QLabel *tableLabel = new QLabel(tr("All Programs"));

QVBoxLayout *buttonLayout2 = new QVBoxLayout;
buttonLayout2 -> addWidget(ShowEdit);
buttonLayout2 -> addWidget(Remove);
//buttonLayout2 -> addStretch();

QHBoxLayout *buttonLayout2_2 = new QHBoxLayout;
buttonLayout2_2 -> addWidget(Quit);
buttonLayout2_2 -> addWidget(OK);

/*******************************************************************************/
/***************************Below is for Table**********************************/
/*******************************************************************************/

PTable = new QTableWidget(10, 10);

//PTable ->setHorizontalHeader(tr("Program Names"));
//inputs->setText(QString::number(row));
//PTable->setItem(row, column, inputs);

QHBoxLayout *PTableLayout = new QHBoxLayout;
PTableLayout ->addWidget(PTable);

/*------------------------------------------------------------------------------*/
/*------------------------construct window--------------------------------------*/
/*------------------------------------------------------------------------------*/

QGridLayout *SecondLayout = new QGridLayout;
SecondLayout -> addWidget(tableLabel, 0, 0);
SecondLayout -> addLayout(PTableLayout, 1, 0);
SecondLayout -> addLayout(buttonLayout2, 0, 1);
SecondLayout -> addLayout(buttonLayout2_2, 2, 0);
setLayout(SecondLayout);
setWindowTitle(tr("Settings"));
}

Window::~Window()
{
delete ui;
}

void Window :: popup()
{
EditWindow* window_3 = new EditWindow(this);
window_3->move(QPoint(550, 100));
window_3->show();
window_3->raise();
}

void Window :: closeBoth()
{
return;
}

void Window :: Saved()
{

return;
}

void Window :: ProgramRemove()
{

return;
} 
#包括“window.h”
#包括“editwindow.h”
#包括“ui_window.h”
#包括
#包括
窗口::窗口(QWidget*父窗口):
QDialog(父级),
ui(新ui::窗口)
{
用户界面->设置用户界面(此);
ShowEdit=新的QPushButton(tr(“编辑”);
ShowEdit->show();
连接(显示编辑、信号(单击())、此、插槽(弹出());
移除=新的QPUSH按钮(tr(“移除”);
删除->显示();
连接(移除,信号(单击()),此,插槽(ProgramRemove());
OK=新的QPushButton(tr(“OK”));
确定->显示();
连接(确定,信号(单击()),此,插槽(已保存());
退出=新的QPushButton(tr(“退出”);
退出->显示();
连接(退出、信号(单击())、此、插槽(关闭());
QLabel*tableLabel=新的QLabel(tr(“所有程序”);
QVBoxLayout*按钮布局2=新的QVBoxLayout;
按钮布局2->addWidget(ShowEdit);
按钮布局2->addWidget(移除);
//按钮布局2->addStretch();
QHBoxLayout*按钮布局2_2=新的QHBoxLayout;
按钮布局2_2->addWidget(退出);
按钮布局2_2->addWidget(确定);
/*******************************************************************************/
/***************************下面是表格**********************************/
/*******************************************************************************/
PTable=新的QTableWidget(10,10);
//PTable->setHorizontalHeader(tr(“程序名”);
//输入->设置文本(QString::number(行));
//PTable->setItem(行、列、输入);
QHBoxLayout*PTableLayout=新的QHBoxLayout;
PTableLayout->addWidget(PTable);
/*------------------------------------------------------------------------------*/
/*------------------------构造窗口--------------------------------------*/
/*------------------------------------------------------------------------------*/
QGridLayout*SecondLayout=新QGridLayout;
SecondLayout->addWidget(tableLabel,0,0);
SecondLayout->addLayout(PTableLayout,1,0);
第二布局->添加布局(按钮布局2,0,1);
第二布局->添加布局(按钮布局2_2,2,0);
设置布局(第二布局);
setWindowTitle(tr(“设置”);
}
窗口::~Window()
{
删除用户界面;
}
void Window::popup()
{
EditWindow*window_3=新的EditWindow(此);
窗口3->移动(QPoint(550100));
窗口3->show();
窗口3->raise();
}
void Window::closeBoth()
{
返回;
}
void Window::Saved()
{
返回;
}
void Window::ProgramRemove()
{
返回;
} 

如果
EditWindow
QDialog
您可以调用exec方法而不是show

从Qt文档中:

intqdialog::exec()[slot]

将对话框显示为模式对话框, 阻止,直到用户关闭它。这个 函数返回一个DialogCode结果

如果对话框是应用程序模式, 用户不能与任何其他用户交互 窗口,直到 他们关闭对话框。如果对话框 是窗口模式,仅与 父窗口被阻止,而 对话框已打开。默认情况下,对话框 是应用程序模式


这样,当EditWindow打开时,用户无法与父窗口交互。

如果
EditWindow
QDialog
您可以调用exec方法而不是show

从Qt文档中:

intqdialog::exec()[slot]

将对话框显示为模式对话框, 阻止,直到用户关闭它。这个 函数返回一个DialogCode结果

如果对话框是应用程序模式, 用户不能与任何其他用户交互 窗口,直到 他们关闭对话框。如果对话框 是窗口模式,仅与 父窗口被阻止,而 对话框已打开。默认情况下,对话框 是应用程序模式


这样,当EditWindow打开时,用户无法与父窗口交互。

这是因为
QDialog
不是模态的,这意味着它不会阻止对其他窗口的输入

您可以使用
QDialog
()中的
setWindowModality()
设置此属性。基本上,您只需执行以下操作:

setWindowModality(Qt::WindowModal);

这是因为
QDialog
不是模式对话框,这意味着它不会阻止其他窗口的输入

您可以使用
QDialog
()中的
setWindowModality()
设置此属性。基本上,您只需执行以下操作:

setWindowModality(Qt::WindowModal);

我把它放在
void Window::popup()
下,结果程序崩溃了。我还注释掉了
窗口_3->show()我把它放在
void Window::popup()
下,结果程序崩溃了。我还注释掉了
窗口_3->show()