对话框关闭后嵌入的 QGraphicsView 不会隐藏
我在模式、showNormal 和 showFullscreen 中调用 QDialog。在正常模式下一切正常。通过按键事件,对话框将按预期关闭。在全屏中,在按键事件之后,对话框将关闭,但 QGraphicsView 将保持在顶部。我尝试过的所有事情(例如关闭/更新视图)都失败了。顶部的 View sta。
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 的小部件,
在 keyPessEvent 上它将发出 closeEvent()。
有什么想法吗?
I call a QDialog in to modes, showNormal and showFullscreen. In normal mode all works fine. With a Keyevent the Dialog closes as expected. In Fullscreen, after a keyevent the Dialog closes, but the QGraphicsView will stay on top. All things i've tried (like closing/updating the view) failed. the View sta on top.
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());
Maybe my structure will help to solve the Problem:
This call the QDialog named GraphicsWidgetDialog.
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();
}
This is the Definition of the 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()));
}
The GraphicsWidget is the Widget that contains the QGraphcisView and Scene
On keyPessEvent it will emit the closeEvent().
Any Idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,自从我编写 Qt 以来已经有一段时间了..但也许您需要调用
gwd->setModal(false)
或在关闭对话框之前离开全屏模式?Sorry, been a while since I've written Qt .. but perhaps you need to call
gwd->setModal(false)
or leave the fullscreen mode before closing the dialog?尝试使graphicsWidget成为GraphicsWidgetDialog的子项。
Try making graphicsWidget to be a child of GraphicsWidgetDialog.