对话框关闭后嵌入的 QGraphicsView 不会隐藏

发布于 2024-09-05 01:53:18 字数 2077 浏览 5 评论 0原文

我在模式、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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

命硬 2024-09-12 01:53:18

抱歉,自从我编写 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?

╰つ倒转 2024-09-12 01:53:18

尝试使graphicsWidget成为GraphicsWidgetDialog的子项。

graphicsWidget = new GraphicsWidget(this);

Try making graphicsWidget to be a child of GraphicsWidgetDialog.

graphicsWidget = new GraphicsWidget(this);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文