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. Possible bug in QGridLayout
Forum Updated to NodeBB v4.3 + New Features

Possible bug in QGridLayout

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 941 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vivaladav
    wrote on last edited by
    #1

    I am working on a tool which needs 3 panels on screen like in the following screenshot:

    wanted layout

    The code I used to recreate that layout is something like

    QGridLayout * layout = new QGridLayout;
    
    QFrame * frame;
    
    frame = new PanelA(this);
    layout->addWidget(frame, 0, 0, 1, 1);
    
    frame = new PanelB(this);
    layout->addWidget(frame, 0, 1, 1, 2);
    
    frame = new PanelC(this);
    layout->addWidget(frame, 1, 0, 1, 3);
    

    All panels inherit from QFrame.

    Everything is fine until the 3 panels are empty, but as soon as I start to add some content to them like for example

    QVBoxLayout * layout = new QVBoxLayout;
    
    layout->addSpacerItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding));
    
    setLayout(layout);
    

    The layout of the main window turns into this:

    wrong layout

    What's really weird is that everything works fine again if I double the column span values and change the window layout code to the following:

    frame = new PanelOpenRepo(this);
    layout->addWidget(frame, 0, 0, 1, 2);
    
    frame = new PanelContributorsSummary(this);
    layout->addWidget(frame, 0, 2, 1, 4);
    
    frame = new PanelContributionCalendar(this);
    layout->addWidget(frame, 1, 0, 1, 6);
    

    This looks a lot like a bug in QGridLayout, but please let me know if I am missing something here.

    Davide Coppola
    blog | Linkedin | Twitter

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      No, it's not a bug, the column span of QGridLayout does not have any link to the relative size of the widgets, it just determines what is put on top of what. To achieve what you want put the top 2 widgets in a QSplitter using setStretchfactor to determine the relative size and then put the QSplitter and the bottom widget in a QHBoxLayout

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      V 1 Reply Last reply
      3
      • VRoninV VRonin

        No, it's not a bug, the column span of QGridLayout does not have any link to the relative size of the widgets, it just determines what is put on top of what. To achieve what you want put the top 2 widgets in a QSplitter using setStretchfactor to determine the relative size and then put the QSplitter and the bottom widget in a QHBoxLayout

        V Offline
        V Offline
        vivaladav
        wrote on last edited by
        #3

        @VRonin said in Possible bug in QGridLayout:

        No, it's not a bug, the column span of QGridLayout does not have any link to the relative size of the widgets, it just determines what is put on top of what.

        Sorry, but that's not true, layout managers are supposed to do exactly that.

        You are right abut this not being a bug though. I was actually missing something: the stretch factor.

        I managed to obtain the layout I wanted with the following code:

        frame = new PanelA(this);
        layout->addWidget(frame, 0, 0, 1, 1);
        
        frame = new PanelB(this);
        layout->addWidget(frame, 0, 1, 1, 1);
        
        frame = new PanelC(this);
        layout->addWidget(frame, 1, 0, 1, 2);
        
        layout->setColumnStretch(0, 1);
        layout->setColumnStretch(1, 2);
        

        Thank you for the alternative solution anyway.

        Davide Coppola
        blog | Linkedin | Twitter

        1 Reply Last reply
        2

        • Login

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