Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem adding QGLWidget to QGridLayout

Problem adding QGLWidget to QGridLayout

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.1k 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.
  • M Offline
    M Offline
    Marga
    wrote on last edited by
    #1

    Hello all,

    I have a QGridLayout set up, where I insert my widgets. I have 3 widgets: QSplitter (dirBrowser), a QTextEdit (textView) and a QGLWidget (windowOpenGL). My code is the following:

    [CODE]void setupUi(QMainWindow *mainWindow)
    {
    if (mainWindow->objectName().isEmpty())
    mainWindow->setObjectName(QString::fromUtf8("mainWindow"));
    mainWindow->resize(800, 600);

    //grid layout
    gridLayout = new QGridLayout();
    layoutWidget = new QWidget(mainWindow);
    layoutWidget->setLayout(gridLayout);
    mainWindow->setCentralWidget(layoutWidget);

    //openGL window
    windowOpenGL = new GLWidget(mainWindow);

    //Splitter
    dirBrowser = new QSplitter(mainWindow); //define the where the browsers will be contained

    //... here I add QListViews and QTreeViews to the splitter

    //Text view
    textView = new QTextEdit(mainWindow);
    textView->setReadOnly(true);

     gridLayout->addWidget(dirBrowser, 0, 0, 1, 1);
     gridLayout->addWidget(textView, 1, 0, 1, 1);
     gridLayout->addWidget(windowOpenGL, 2, 0, 1, 1);
    

    // .. here there are some connects(...)
    }[/CODE]

    Using this code as it is, the window does not display the OpenGL window. However, if I don't add the QTextEdit to the grid layout, it displays normally. The strange thing is that if instead of adding QTextEdit to the grid I add, for a example, a simple button, the OpenGL widget is displayed correctly as well.

    What am I missing??? I would appreciate SO MUCH your help!!

    Thanks in advance!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #2

      Cannot see anything obviously wrong with that code.
      Except maybe that you are passing the mainWindow as parent to widgets that will have the layoutWidget as parent. Since you are putting all the widgets in layouts you don't really have to pass a parent argument to the constructors at all, so I would remove that.

      Another option would be to try a QVBoxLayout instead.
      Since you seem to be using only one column, a QVBoxLayout should do the same thing (and could work better, if you are lucky).

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ludde
        wrote on last edited by
        #3

        And one more thing I just remembered - are you sure the OpenGL window is not there, maybe it's just very small - I think the default size may be very small, possibly even with zero width and height.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marga
          wrote on last edited by
          #4

          Hi Ludde,

          Thanks a lot!! Your reply was really useful. I realised later that I was passing the wrong parent to the widgets, but now I will follow your advice of simply not passing anything at all :)

          I discarded the possibility of the size of the widget being 0 because the problem persisted after setting a fixed size to the QTextEdit widget. BUT after playing around with other functions it turns out you are right! If I set a minimum size to the OpenGL widget, I can see it on the screen! I am new to Qt and didn't know widgets could have size 0 and not be shown on the screen. Now that I know the solution it looks so obvious :P

          Thanks a million for taking the time to reply, I really appreciate it!

          Margara

          1 Reply Last reply
          0
          • L Offline
            L Offline
            ludde
            wrote on last edited by
            #5

            No problem, just happy to be able to help out!

            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