I am developing an application in Qt 4.8.4, in which I do the following:
I subclass QGridLayout as follows:
class Viewer : public QGridLayout
{
Q_OBJECT
...................
private:
// Objects
/// Maximize button object
ViewerGeneric* viewerGeneric;
/// Maximize button object
QPushButton* btnMaximize;
/// Close button object
QPushButton* btnClose;
/// Connect button object
QPushButton* btnConnect;
/// Central viewer layout object
QGridLayout* viewer;
/// Indicates the row position in the main grid
unsigned int row;
/// Indicates the column position in the main grid
unsigned int col;
};
Then in the constructor I do something like this:
// Create the objects
btnMaximize = new QPushButton("max");
btnClose = new QPushButton("close");
btnConnect = new QPushButton("connect");
// Add the horizontal toolbar
QHBoxLayout* toolbar = new QHBoxLayout();
toolbar->setSizeConstraint(QLayout::SetMinimumSize);
toolbar->addItem(new QSpacerItem(0, 0,
QSizePolicy::Expanding, QSizePolicy::Minimum));
toolbar->addWidget(btnMaximize);
toolbar->addWidget(btnClose);
// Add the 'Connect' button
viewer = new QGridLayout();
viewer->addWidget(btnConnect);
// Add the widgets
this->addItem(toolbar, 0, 0);
this->addItem(viewer, 0, 0, 2);
But, in the end, when I show the Viewer class in my main window the window is completely blank! Hope anybody can help me. Thank you.
Cheers,
If parent widget is already visible, you need to call show()
method of the later added widgets to make them visible.
Finally I have found the solution:
For adding layouts into layouts, use addLayout() function instead of addItem(). I do not really know which is the difference but it works.
Thanks for your comments!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With