tags:

views:

25

answers:

1

I need the way to setup widgets inside other widget with different layouts...

it is something like we have widget divided by one layout into two parts with labels, and this widget have other widget inside with layout like on attached image alt text

and we have only 4 widgets: main widget, label one widget, label two widget, button widget, and for button use one vertical and two horizontal stretch

Can some body point me to right way do it? Thanks.

A: 

Create QVBoxLayout, then add two QHBoxLayouts to it. In top QHBoxLayout add labels, in bottom one add stretch, button, stretch.

window example

#include <QString>
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLocale>

int main(int argc, char** argv){
    QApplication app(argc, argv);

    QWidget widget;

    QVBoxLayout* vLayout = new QVBoxLayout(&widget);
    QHBoxLayout* topLayout = new QHBoxLayout();
    QHBoxLayout* bottomLayout = new QHBoxLayout();
    QLabel* label1 = new QLabel(QObject::tr("Label1"));
    QLabel* label2 = new QLabel(QObject::tr("Label2"));
    label1->setAlignment(Qt::AlignCenter);
    label2->setAlignment(Qt::AlignCenter);
    QPushButton* btn1 = new QPushButton(QObject::tr("The Button!!!!"));
    topLayout->addWidget(label1);
    topLayout->addWidget(label2);
    bottomLayout->addStretch();
    bottomLayout->addWidget(btn1);
    bottomLayout->addStretch();
    vLayout->addLayout(topLayout);
    vLayout->addLayout(bottomLayout);

    widget.show();

    return app.exec();
}
SigTerm
no bottom and upper layouts in this case... i mean button positionion inside widget separetly from labels.maybe it is not so hard for you make draft application? thanks for replyI can do one layout with labels, and second layout with sublayout with botton and two stretch elements.... but how merge this two different layouts inside one main widget?...
vinnitu
@vinnitu: Qt 4 has documentation and tutorials. http://doc.qt.nokia.com/
SigTerm
ok... we don't understand each other... let's say the button need to bee in center of widget (horisontal and vertical)... so what changes we need to do? label one must be in center one half of widget, and label two must me in center of second half of widget...
vinnitu
@vinnitu: you want to place button on top of the label, so it will hide part of underlying controls? In this case your description doesn't match your picture.
SigTerm
yes, it will hide part of both labels in this case, so how do you think it is possible do with qt?ofcause it is possible to set position with coordinates (x, y) moveto and so on, but question is do it with using layout system
vinnitu
@vinnitu: I don't think you can do it using default layouts, because widgets aren't supposed to be overlapping in layouts, and I don't exactly see anything similar to "zorder" in Qt 4. However, you could make custom widget (that either contains or emulates two labels), or you could try making custom layout class. Making widget will be easiest - just paint whatever text you want (i.e. two labels) during paintEvent. Then add button to this widget using standard layouts.
SigTerm