我将QDialog调用到模式,showNormal和showFullscreen。在正常模式下一切正常。随着Keyevent,Dialog按预期关闭。在Fullscreen中,在关键事件关闭后,对话框关闭,但QGraphicsView将保持在最顶层。我尝试过的所有东西(比如关闭/更新视图)都失败了。视图位于顶部。
view = new QGraphicsView(scene);
view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
view->setFrameStyle(QFrame::NoFrame);
view->setBackgroundBrush(Qt::white);
view->setRenderHints(QPainter::Antialiasing);
view->setSceneRect(0,0,resolution.x(),resolution.y());
也许我的结构将有助于解决问题:
这会调用名为GraphicsWidgetDialog的QDialog。
void DemoArrowDialog::setDemo() {
gwd->graphicsWidget->setListenKeyEvents(true);
gwd->setWindowTitle("Demo");
gwd->setFixedSize(500,500);
gwd->restoreGeometry(settings);
gwd->setContentsMargins(0,0,0,0);
gwd->setModal(false);
gwd->showNormal();
gwd->graphicsWidget->show();
gwd->setFocus();
}
void DemoArrowDialog::setFullScreenDemo() {
settings = gwd->saveGeometry();
gwd->graphicsWidget->setListenKeyEvents(true);
gwd->setContentsMargins(0,0,0,0);
gwd->setModal(true);
gwd->graphicsWidget->showFullScreen();
gwd->showFullScreen();
gwd->setFocus();
}
这是GraphicsWidgetDialog的定义
GraphicsWidgetDialog::GraphicsWidgetDialog(QWidget *parent) :
QDialog(parent) {
graphicsWidget = new GraphicsWidget;
QGridLayout *layout = new QGridLayout;
layout->addWidget(graphicsWidget);
layout->setContentsMargins(0,0,0,0);
graphicsWidget->loadConfig();
graphicsWidget->loadArrowConfig("Arrow");
graphicsWidget->setArrowPosition(arrowPosition(arrowCenter));
graphicsWidget->update();
setLayout(layout);
connect(graphicsWidget,SIGNAL(closeEvent()),this,SLOT(reject()));
}
GraphicsWidget是包含QGraphcisView和Scene
的Widget在keyPessEvent上,它将发出closeEvent()。
任何想法?
答案 0 :(得分:0)
很抱歉,自从我写了Qt以来已经有一段时间..但是你可能需要在关闭对话框之前拨打gwd->setModal(false)
或离开全屏模式?
答案 1 :(得分:0)
尝试使graphicsWidget成为GraphicsWidgetDialog的孩子。
graphicsWidget = new GraphicsWidget(this);