Reputation: 163
I'm developing an application with Qt on embedded Linux. The platform plugin is EGLFS.
The main of the application is:
QApplication a(argc, argv);
MainWindow mainWindow;
CentralWidget centralWidget(&mainWindow);
centralWidget.setObjectName("centralWidget");
centralWidget.setStyleSheet("CentralWidget#centralWidget {background-color: red;}");
centralWidget.setGeometry(50, 50, 500, 500);
mainWindow.show();
return a.exec();
MainWindow is a class which inherits QMainWindow, CentralWidget is a class that inherits QWidget. The implementations of the constructors of the MainWindow and CentralWidget are:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {}
CentralWidget::CentralWidget(QWidget *parent) : QWidget(parent) {}
When launching the application I've observed that the CentralWidget is never shown. I've tried with no success to force the show of the CentralWidget but nothing happens.
Is my code wrong or am I facing a bug?
Upvotes: 2
Views: 956
Reputation: 163
The problem is related to the EGLFS platform plugin. From the Qt docs:
As of Qt 5.3, eglfs supports a single, fullscreen GL window (for example, an OpenGL-based QWindow, a QQuickView or a QGLWidget). Opening additional OpenGL windows or mixing such windows with QWidget-based content is not supported and will terminate the application with an error message.
Reference: http://doc.qt.io/qt-5/embedded-linux.html#eglfs
Therefore the opening of additional windows, mixed with QWidget-based content is not supported.
Upvotes: 0
Reputation: 7146
For a widget to be shown inside the QMainWindow
, you have to set it as central widget using QMainWindow::setCentralWidget
. The mainwindow itself consists of multiple parts, and the one you want to fill is the "Central Widget":
To do this, simply call
mainWindow.setCentralWidget(¢ralWidget);
before you show the window and it should work. (Please note that setting the geometry on the central widget won't work, it will be resized to the mainWindow
. Resize that one instead).
If you don't want to replace the central widget, but rather add a new child to it, all you have to do is to change the widgets parent to the central widget (instead of the mainwindow itself):
CentralWidget centralWidget(mainWindow.centralWidget());
Please note that the central widget needs to be set before, otherwise NULL
is returned. Since your MainWindow is a custom class, you propably already have a central widget. If not, and you just want an empty container, fill it with a simple QWidget
before using it:
mainWindow.setCentralWidget(new QWidget());//No parent required, QMainWindow takes ownership
CentralWidget centralWidget(mainWindow.centralWidget());
(Image taken from: https://doc.qt.io/qt-5/qmainwindow.html#details)
Upvotes: 2