Why a QWidget is not shown when set as parent of another one?



  • 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?


  • Moderators

    Hi!
    You forgot to call mainWindow.setCentralWidget(&centralWidget);

    Beware that mainWindow will take control over centralWidget and delete it when it needs to. So you need to do it like this:

    CentralWidget *centralWidget = new CentralWidget(&mainWindow);
    mainWindow.setCentralWidget(centralWidget);
    


  • @Wieland Hello! First of all thanks for your reply. I've already tried to use "setCentralWidget" but nothing happens. I think that the problem is related to EGLFS. Reading the doc: http://doc.qt.io/qt-5/embedded-linux.html#eglfs I've found that:

    "There are further restrictions for OpenGL-based windows. 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."


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.