Solved QTool Dialog with OpenGL Stuff in Qt 5.5
-
Hi all,
I have a problem with QTool dialogs and OpenGL using Qt 5.5. I noticed that this OpenGL-widgets-thing has been updated in Qt 5.4.
So I think my problem has something to do with these updates.I am using Windows 7 64Bit with NVidia Geforce 840M, 8GB Ram, Qt 5.5 and Qt 5.3.2 with Qt Creator and Visual Studio 2010 Compiler.
I have reduced my program to a simple program which has the same problem.
I have a QTool dialog with shows some OpenGL stuff.
Now the bevavior of switching to fullscreen differs to Qt 5.3.2 as follows:- the screen is flickering, it does not in Qt 5.3.2.
- the QTool dialog seems to be hidden, but when you click one the last dialog's position (where it was before) the screen is flickering again and the dialog is visible in front of the mainwindow. Clicking on the mainwindow again hides the dialog again (with flickering).
- the menubar has a similar behavior as the dialog. It is not visible but it is there, you can click on actions and they will be triggered. But you don't see any submenus or actions.
This OpenGL dialog is working if it is a normal and not a QTool Dialog.
Strange things going on there. Any ideas, explanations, suggestions, comments?My Code:
main.cpp is default contructed by Qt Creator.
mainwindow.ui is default contructed by Qt Creator.mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #if QT_VERSION >= QT_VERSION_CHECK( 5, 4, 0 ) #include <QtWidgets> #else #include <QGLWidget> #endif #if QT_VERSION >= QT_VERSION_CHECK( 5, 4, 0 ) class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions #else class GLWidget : public QGLWidget #endif { Q_OBJECT public: explicit GLWidget( QWidget* parent = 0 ); ~GLWidget() {} }; // ------------------------- namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow( QWidget* parent = 0 ); ~MainWindow(); public slots: void onClicked(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDialog> #include <QGridLayout> #include <QLabel> // ------------------------- GLWidget::GLWidget( QWidget* parent ) #if QT_VERSION >= QT_VERSION_CHECK( 5, 4, 0 ) : QOpenGLWidget( parent ) , QOpenGLFunctions() #else : QGLWidget( parent ) #endif { } // ------------------------- MainWindow::MainWindow( QWidget* parent ) : QMainWindow( parent ), ui( new Ui::MainWindow ) { ui->setupUi( this ); QPushButton* pb = new QPushButton( "Fullscreen", this ); connect( pb, SIGNAL( clicked() ), this, SLOT( onClicked() ) ); QGridLayout* layout = new QGridLayout( ui->centralWidget ); layout->addWidget( pb ); QMenuBar* menuBar = new QMenuBar( this ); QMenu* fileMenu = menuBar->addMenu( "File" ); fileMenu->addAction( "Quit", this, SLOT( close() ) ); setMenuBar( menuBar ); QDialog* myDialog = new QDialog( this ); QGridLayout* gridLayout = new QGridLayout( myDialog ); gridLayout->setMargin( 0 ); gridLayout->addWidget( new GLWidget( myDialog ) ); // remove to keep it work as normal dialog myDialog->setWindowFlags( Qt::Tool ); myDialog->resize( 200, 200 ); myDialog->show(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::onClicked() { if( isFullScreen() ) showNormal(); else showFullScreen(); }
-
Hi,
I'd recommend checking with the current 5.6 beta to see if you are still experiencing the same stuff, if so, please take a look at the bug report system to see if something known. If not please consider opening a new report providing your example as a minimal compilable project.
-
Hello,
Your problem is probably related to QTBUG-41309 (similar to QTBUG-7556). I stumbled upon those two recently when I was trying to show a main window containing aQOpenGLWidget
in full screen. You could try this workaround by putting it in yourQWidget::showEvent
override:void YourWidget::showEvent(QShowEvent * event) { event->accept(); // Handle maximize/restore ... // Workaround for QTBUG-41309, we want the window maximized QRect geometry = QApplication::desktop()->screenGeometry(); setGeometry(geometry); setFixedSize(geometry.width(), geometry.height() + 1); }
I hope this helps.
Kind regards. -
Hello
this kind of a "pseudo fullscreen" helped.
But I didn't solve it with the showEvent, becauseshowFullScreen()
does not entershowEvent()
when the window is already shown.
I used a button (and an action) to switch to fullscreen and back to normal view, so this is how I do it. And that works for me, thankx.
And it's not even flickering. :-)void MainWindow::onClicked() { if( m_fullscreen ) { m_fullscreen = false; setMinimumSize( 0, 0 ); setMaximumSize( 16777215, 16777215 ); setGeometry( m_defaultGeometry ); showNormal(); } else { m_fullscreen = true; m_defaultGeometry = geometry(); QRect rectGeometry = QApplication::desktop()->screenGeometry(); setGeometry( rectGeometry ); setFixedSize( rectGeometry.width(), rectGeometry.height() + 1 ); } }
-
@stvokr
Sure, you could use the code where appropriate, it's not needed to be in the show event exactly. Glad it worked, it took me some time to obtain that precious information, so I gladly disseminate it further ;)