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

S. Aguinaga sa_jr at yahoo.com
Wed Jan 14 21:22:11 CET 2009


Efan, 
Thank you, I appreciate and value your help.

I'm rather new to Qt, so in terms of what I'm trying to do and following with the same example as shown below, 
so if I define 2 vBoxes for example I want to put them in a HBox:
vbox->addWidget(button1);
vbox->addWidget(label1);
vbox2->addWidget(button2);
vobx2->addWidget(label2);
For hbox, do I add the layouts vbox, like this ?
hbox->addLayout(vbox,0,0);
hbox->addLayout(vbox2,1,0);


or do I 
centralWidget()->addLayout(vbox,0,0);

centralWidget()->addLayout(vbox2,1,0);
or
QGroupBox   *groupBox = new QGroupBox(tr("G1"));
centralWidget()->groupBox->setLayout(vbox_c0);

I guess I don't know how to call the layout() function...    :(




________________________________
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/20090114/821d2c90/attachment.html 


More information about the Qt-interest-old mailing list