[SOLVED] help with layout
Hi,
in a widget I’ve got the following layout setup:
- panelMaster->setLayout( hLayout );
- hLayout->addWidget( tableViewMaster );
- buttons->setLayout( vLayout );
- vLayout->addWidget( buttonAddMasterElement );
- vLayout->addWidget( buttonEditMasterElement );
- vLayout->addWidget( buttonDeleteMasterElement );
- vLayout->addWidget( buttonRefreshMasterElement );
- hLayout->addWidget( buttons );
The idea is to have the tableview to occupy the most and central space of the widget, with a vertical set of buttons on the right. However, when I set up this widget as the central widget of my mainwindow the widget itself occupies less than the whole window space and I cannot resize the table. What am I doing wrong?
5 replies
Well the method that performs the setup of the gui from the constructor of the widget (and the constructor does nothing else) is:
- void UserView::setUpPanelMaster()
- {
- ...
- ...
- panelMaster->setLayout( hLayout );
- hLayout->addWidget( tableViewMaster );
- buttons->setLayout( vLayout );
- vLayout->addWidget( buttonAddMasterElement );
- vLayout->addWidget( buttonEditMasterElement );
- vLayout->addWidget( buttonDeleteMasterElement );
- vLayout->addWidget( buttonRefreshMasterTable );
- hLayout->addWidget( buttons );
I think I fixed all the paret-child relationships.
In the mainwindow I’ve got:
- setCentralWidget( uview );
with uview as my widget and no layout set up for the main window.
To make it clear:
- uview is a subclass of QWidget that in its constructor calls setUpPanelMaster:
- panel master is simply used as a panel within uview, since I will reach the condition when I have two or more panels with different widgets inside the uview (but at the moment I’m using only one).
- panel master is set up with a horizontal layout, on the left there is the tableview, and on the right there is vertical layout with the buttons.
- in the main window class I create a new uiview and place it as central widget without any further layout setup.
I managed it in the end!
The problem was in the constructor of the UserView, that while it was setting up a layout, it was not adding widgets to it. The final code that works is therefore:
- // set up a vertical layout
- setLayout( vLayoutMain );
- setUpPanelMaster();
- vLayoutMain->addWidget( panelMaster );
and now it is displayed correctly.
You must log in to post a reply. Not a member yet? Register here!


