Results 1 to 4 of 4

Thread: Vertical alignment for QComboBox

  1. #1
    Join Date
    Aug 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Vertical alignment for QComboBox

    Hello,

    I am trying to position a QComboBox in a layout but I cannot succeed to do it, could you help me ?

    Indeed, I have a QVBoxLayout in which I have added : a QLabel (visible), a QComboBox (visible) and a QWidget (not visible at the beginning). The result is that the QLabel and the QCombobox are positioned at the bottom of the QVBoxLayout. When I turn the QWidget to visible, both QLabel and QComboBox goes at the top (pushed by the QWidget).

    Is there a way to have, from the beginning, the QLabel and the QComboBox positionned at the top. I have found "setAlignment(Qt::AlignTop)" for the QLabel but nothing for the QComboBox.

    Thanks in advance.


    Added after 5 minutes:


    I found that : "setDirection(QBoxLayout::TopToBottom)", applied to the QVBoxLayout.

    However, QLabel is now positionned in the middle and the QComboBox at the bottom of the QLayout.
    Last edited by Julieng031; 17th April 2014 at 11:46.

  2. #2
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Vertical alignment for QComboBox

    Try setting QSizePolicy of QLabel.
    I see that QSizePolicy also has void QSizePolicy::setVerticalPolicy(Policy policy) function.

    So something like label->setVerticalPolicy(QSizePolicy::Fixed) might solve it.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Vertical alignment for QComboBox

    One other thing you can try is adding a QSpacerItem or a stretch, so it takes the available space if the third widget is hidden.

    Cheers,
    _

  4. #4
    Join Date
    Aug 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Vertical alignment for QComboBox

    I tried to add "Qt::AlignTop" for the third parameter of "addWidget()" but it did not worked.

    Finally, I solved it by adding "QVBoxLayout->setAlignment(Qt::AlignTop)".

    Thanks for your answers !

Similar Threads

  1. Vertical QComboBox
    By Momergil in forum Qt Programming
    Replies: 6
    Last Post: 14th February 2014, 13:19
  2. QGraphicsTextItem Vertical text alignment
    By mbra in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2011, 03:12
  3. Alignment in QComboBox
    By Naami in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2010, 14:53
  4. Replies: 1
    Last Post: 21st November 2009, 20:38
  5. Vertical alignment of rows in a tree view
    By Micawber in forum Qt Programming
    Replies: 9
    Last Post: 17th June 2008, 21:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.