[Qt-interest] [ Solved ] What's the deal with centralWidgets (Qmainwindow) and QLayouts

S. Aguinaga sa_jr at yahoo.com
Fri Jan 16 00:18:28 CET 2009


There are two parts to this solution:

For the Central Widget:
I defined a class and added 3 vertical boxes and one horizontal box.

I added the vboxes to the hbox and omitted the setLayout(hbox) command.

ToneAudCentralWidget::ToneAudCentralWidget(QWidget *parent) 
{
QSpinBox*left_dB_spb,
*right_dB_spb,
*stepSize_spb;
QComboBox*sigTypeComboBox,
*xducerTypeComboBox,
*earChannelComboBox,
*outputFormatComboBox;
QPushButton *fmOnOffToggleButton,
*onePlotToggleB;

QHBoxLayout *c_widget = new QHBoxLayout(this);
QVBoxLayout *vbox0 = new QVBoxLayout();
QVBoxLayout *vbox1 = new QVBoxLayout();
QVBoxLayout *vbox2 = new QVBoxLayout();
:
:

:

c_widget->addLayout(vbox0);
c_widget->addLayout(vbox1);
c_widget->addLayout(vbox2);
//c_widget->setLayout(c_widget);
}

If you are doing this on Docking Widget, leave the QHBoxLayout by itself do not specify parent widget, in other words:
     QHBoxLayout *hbox = new QHBoxLayout;
     QVBoxLayout *vbox0 = new QVBoxLayout;
QVBoxLayout *vbox1 = new QVBoxLayout;
QVBoxLayout *vbox2 = new QVBoxLayout;

Then use a widget to set your layout and add the widget to the dock (example here is my Bottom Docking Widget):

     QWidget *dockBotwi = new QWidget;
dockBotwi->setLayout(hbox);
dock->setWidget(dockBotwi);
addDockWidget(Qt::BottomDockWidgetArea, dock);

// Sal 

________________________________
From: Efan Harris <efanharris at gmail.com>
To: S. Aguinaga <sa_jr at yahoo.com>
Cc: qt-interest at trolltech.com
Sent: Wednesday, January 14, 2009 11:26:55 AM
Subject: Re: [Qt-interest] What's the deal with centralWidgets (Qmainwindow) and QLayouts

QMainWIndow by default has Layout so when you add a central widget to it, is is taken care by Mainwindow's layout. 
You can call layout() function to get the pointer of this default layout.

Efan


On Wed, Jan 14, 2009 at 9:19 AM, S. Aguinaga <sa_jr at yahoo.com> wrote:



To design a central widget consisting of 3 vhboxlayouts what is the right way to set the 
layout?  I have tried using QVBoxes inside of QHBoxes, QGrids, an GroupBoxes, and I get the same 
error message when the window opens.  I'm sure I'm missing something fundamental.


I have widgets (pusbuttons, labels, &c. ) on 3 diff vboxes, then one QHBoxLayout that I 
want to add the vboxes, but I keep getting a warning when I run the program I get:

"QLayout: Attempting to add QLayout "" to ToneAudWindow "", which already has a layout"

and I haven't found a useful answer.

[code]
ToneWindow::ToneWindow() {  
  createDockingPanels();  //these are fine
  createCentralWidget();
}
void ToneWindow::createCentralWidget() {
  QGroupBox   *groupBox = new QGroupBox(tr("G1"));
    
    freqLCD        = new QLCDNumber(5);
    freqLCD->setSegmentStyle(QLCDNumber::Filled);
    freqLCD->display( 400 );
    vbox_c0 = new QVBoxLayout(this); // here I have only one Vertical group box
    vbox_c0->addWidget(new QLabel(tr("Frequency")));
    vbox_c0->addWidget(freqLCD);
    groupBox->setLayout(vbox_c0);
    setCentralWidget(groupBox);
}
[/code]

Reference: 
http://lists.trolltech.com/qt-interest/2008-06/thread00514-0.html

Please, any help will be appreciated.

// Sal

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090115/11f80afe/attachment.html 


More information about the Qt-interest-old mailing list