0
如果某個QDialog
實例是exec()
未使用,是否可能會阻止整個操作系統,直到用戶關閉對話框?在下面的最小例子中,對話框僅阻止其父窗口小部件,但不阻止Qt應用程序之外的操作系統元素。將QDialog模式設置爲操作系統
rootwindow.h
#ifndef ROOTWINDOW_H
#define ROOTWINDOW_H
#include <QApplication>
#include <QMainWindow>
#include <QtDebug>
#include <QDialog>
#include <QPushButton>
#include <QMessageBox>
#include <QBoxLayout>
class RootWindow : public QMainWindow
{
Q_OBJECT
private:
QWidget *widgetCentral;
QBoxLayout *layoutMain;
QPushButton *button;
QDialog *dialog;
public:
RootWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0);
~RootWindow();
private slots:
void slotClicked();
};
#endif // ROOTWINDOW_H
rootwindow.cpp
#include "rootwindow.h"
RootWindow::RootWindow(QWidget *parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
{
setCentralWidget(widgetCentral = new QWidget);
widgetCentral->setLayout(layoutMain = new QBoxLayout(QBoxLayout::LeftToRight));
layoutMain->addWidget(button = new QPushButton("Click me"));
dialog = new QDialog(this);
dialog->setModal(true);
dialog->setWindowModality(Qt::ApplicationModal);
connect(button, &QPushButton::clicked, this, &RootWindow::slotClicked);
}
RootWindow::~RootWindow()
{
}
void RootWindow::slotClicked()
{
int i = dialog->exec();
qDebug() << "Dialog result: " << i;
}
的main.cpp
#include "rootwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
RootWindow w;
w.show();
return a.exec();
}
Afaik這是不可能的Qt – Evgeny
還沒有與其他框架;-) –
...這是一件好事。 –