Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Why a QWidget is not shown when set as parent of another one?

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

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 739 Views
  • 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 Offline
    G Offline
    Grynium
    wrote on last edited by
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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
      0
      • ? A Former User

        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 Offline
        G Offline
        Grynium
        wrote on last edited by
        #3

        @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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved