[Qt-interest] QHBoxLayout alignment issue

Markus Franke Franke.M at sebakmt.com
Fri Mar 4 10:58:32 CET 2011


Dear all,

I have three widgets (QLabel's) which I would like to place into a 
QHBoxLayout.

---------------------------------------------------------------------------------------
| Widget 1      |       Widget 2        |       Widget 3 |
---------------------------------------------------------------------------------------

Widget 1 should always be aligned left, Widget 3 should always be aligned 
right. 
Widget 2 should always be centered in the middle of Widget 1 and Widget 3, 
i.e. the gaps Widget1-Widget2 and Widget2-Widget3 should always be of 
equal size.

I did something like below but Widget 2 still is not equally aligned 
between Widget 1 and Widget 3.

---snip---
        Widget1->setAlignment(Qt::AlignLeft);
        Widget2->setAlignment(Qt::AlignHCenter);
        Widget3->setAlignment(Qt::AlignRight);

        QHBoxLayout* HValues = new QHBoxLayout;

        HValues->addWidget(Widget1,                     0, Qt::AlignLeft);
        HValues->addWidget(Widget2,                     1, 
Qt::AlignCenter);
        HValues->addWidget(Widget3,                     2, 
Qt::AlignRight);
        HValues->setSpacing(5);
---snip---

How can I achieve this behaviour with QHBoxLayout?

Thanks for help and with best regards,
Markus  Franke



"Disclaimer: This message is intended only for the use of the individual 
or entity to
which it is addressed and may contain information which is privileged, 
confidential, proprietary,
or exempt from disclosure under applicable law. If you are not the 
intended recipient or the person
responsible for delivering the message to the intended recipient, you are 
strictly prohibited from
disclosing, distributing, copying, or in any way using this message. If 
you have received this 
communication in error, please notify the sender and destroy and delete 
any copies you may have
received."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110304/2ccd850e/attachment.html 


More information about the Qt-interest-old mailing list