QMainWindow 打开文件对话框中断并且没有响应

QMainWindow Open File dialog cut off and doesn't respond

我在 Qt5 中的打开文件对话框被切断,它不响应任何鼠标点击。我正在使用 OpenGLWindow(根据 http://doc.qt.io/qt-5/qtgui-openglwindow-example.html) inside the central widget of the QMainWindow (per http://blog.qt.io/blog/2013/02/19/introducing-qwidgetcreatewindowcontainer/)。如果我没有将中央小部件设置为我的 OpenGLWindow,则打开文件对话框有效,但是一旦我在中央小部件中使用 OpenGLWindow,就会出现此问题。请参阅下面的屏幕截图。关于如何修复或调试它的任何想法?

main.cpp:

    ...
    QApplication app(argc, argv);
    QSurfaceFormat format;
    format.setSamples(16);
    MainWindow mainWin;
    MyOpenGLWindow window();
    window.setFormat(format);
    window.setAnimating(true);

    QWidget *container = QWidget::createWindowContainer(&window);
    mainWin.setCentralWidget(container);

#if defined(Q_OS_SYMBIAN)
    mainWin.showMaximized();
#else
    mainWin.show();
#endif
....

mainwindow.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

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

void MainWindow::on_actionOpen_File_triggered()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "/home");
}

mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
private slots:
    void on_actionOpen_File_triggered();
};

#endif // MAINWINDOW_H

mainwindow.ui:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget"/>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>25</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuTest_Window">
    <property name="title">
     <string>File</string>
    </property>
    <addaction name="actionOpen_File"/>
   </widget>
   <addaction name="menuTest_Window"/>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
  <action name="actionOpen_File">
   <property name="text">
    <string>Open File</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections/>
</ui>

似乎解决这个问题的方法是使用QOpenGLWidget (per https://blog.qt.io/blog/2014/09/10/qt-weekly-19-qopenglwidget/)。使用 OpenGL 的 QWindow 方法似乎不能与其他 QWidgets 很好地混合。我现在成功地将我的应用程序转移到使用 QOpenGLWidget 并且它有效!