[Qt-interest] little help with layouts
Luca Ferrari
fluca1978 at infinito.it
Mon Apr 27 12:44:34 CEST 2009
Hi,
moving my first steps in QT I got a behaviour I cannot understand. The window
should display two labels and a few buttons, with different layouts, but I'm
not getting what is wrong with the following code (that shows nothing):
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QHBoxLayout* mainLayout = new QHBoxLayout();
this->setLayout( mainLayout );
// a container for labels
QWidget* container = new QWidget( );
this->signalLabel = new QLabel("No signal yet!");
this->slotLabel = new QLabel("No slot yet!");
QVBoxLayout* layout = new QVBoxLayout( );
layout->addWidget( this->signalLabel );
layout->addWidget( this->slotLabel );
QWidget* buttonContainer = new QWidget( );
QVBoxLayout* buttons = new QVBoxLayout( );
buttonContainer->setLayout( buttons );
for(int i = 0; i < 2; i ++ ){
QPushButton* currentButton = new QPushButton( QString::number(i) );
buttons->addWidget( currentButton );
}
mainLayout->addWidget( container );
mainLayout->addWidget( buttonContainer );
}
The idea is:
1) set the main layout of the window
2) create the labels into a container widget and add them to such container
using its layout;
3) create a container for buttons and add buttons to the container
4) add the two containers to the above main layout.
Any suggestion is welcome.
Thanks,
Luca
More information about the Qt-interest-old
mailing list