Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    Mobile and Embedded
    2
    3
    562
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      Grynium last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        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);
        
        G 1 Reply Last reply Reply Quote 0
        • G
          Grynium @Guest last edited by

          @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."

          1 Reply Last reply Reply Quote 0
          • First post
            Last post