Basic question, labels in vertical layout not showing...
-
Sorry if this is one of those basic questions. I have a window on the display, I want to add quick debug information to the form. I have added a label which was simple enough:
mplblAddress = new QLabel(this); mplblAddress->setText(cstrAddress);
The above works, now I want two lines so I thought, add a QVBoxLayout then add both labels to the layout:
QVBoxLayout* pobjVBLO(new QVBoxLayout(this)); mplblAddress = new QLabel; mplblAddress->setText(csrAddress); pobjVBLO->addWidget(mplblAddress); mplblInfo = new QLabel; mplblInfo->setText(cstrInfo); pobjVBLO->addWidget(mplblInfo);
Nothing is displayed, I also tried:
QVBoxLayout* pobjVBLO(new QVBoxLayout; mplblAddress = new QLabel; mplblAddress->setText(csrAddress); pobjVBLO->addWidget(mplblAddress); mplblInfo = new QLabel; mplblInfo->setText(cstrInfo); pobjVBLO->addWidget(mplblInfo); setLayout(pobjVBLO);
Nothing is displayed this way either. What haven't I done?
this is the window class.
-
And here we have a winner: QMainWindow. That class already has a layout that does all the docking, toolbar, etc handling and that cannot be replaced.
@SGaist , ok, fixed by adding the following:
QWidget* pobjWidget(new QWidget(this)); QVBoxLayout* pobjVBLO(new QVBoxLayout); pobjVBLO->addWidget(mplblAddress); pobjVBLO->addWidget(mplblInfo); pobjWidget->setLayout(pobjVBLO); setCentralWidget(pobjWidget);
-
Sorry if this is one of those basic questions. I have a window on the display, I want to add quick debug information to the form. I have added a label which was simple enough:
mplblAddress = new QLabel(this); mplblAddress->setText(cstrAddress);
The above works, now I want two lines so I thought, add a QVBoxLayout then add both labels to the layout:
QVBoxLayout* pobjVBLO(new QVBoxLayout(this)); mplblAddress = new QLabel; mplblAddress->setText(csrAddress); pobjVBLO->addWidget(mplblAddress); mplblInfo = new QLabel; mplblInfo->setText(cstrInfo); pobjVBLO->addWidget(mplblInfo);
Nothing is displayed, I also tried:
QVBoxLayout* pobjVBLO(new QVBoxLayout; mplblAddress = new QLabel; mplblAddress->setText(csrAddress); pobjVBLO->addWidget(mplblAddress); mplblInfo = new QLabel; mplblInfo->setText(cstrInfo); pobjVBLO->addWidget(mplblInfo); setLayout(pobjVBLO);
Nothing is displayed this way either. What haven't I done?
this is the window class.
-
Hi,
Any chances that you already have a layout on that widget ?
-
@SGaist , I don't think so because there is no UI and the class is derived from QMainWindow, the constructor has nothing in it....however I will call layout to see what is returned.
[Edit], so I added:
QLayout* pobjLayout(this->layout());
And an address is returned NOT null, so where or what would be setting this?
-
And here we have a winner: QMainWindow. That class already has a layout that does all the docking, toolbar, etc handling and that cannot be replaced.
-
And here we have a winner: QMainWindow. That class already has a layout that does all the docking, toolbar, etc handling and that cannot be replaced.
@SGaist , ok, fixed by adding the following:
QWidget* pobjWidget(new QWidget(this)); QVBoxLayout* pobjVBLO(new QVBoxLayout); pobjVBLO->addWidget(mplblAddress); pobjVBLO->addWidget(mplblInfo); pobjWidget->setLayout(pobjVBLO); setCentralWidget(pobjWidget);