Results 1 to 3 of 3

Thread: QGroupBox formatting

  1. #1
    Join Date
    Jul 2011
    Location
    On Earth
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGroupBox formatting

    I have a QGroupBox of radio buttons. I have added the buttons to the horizontal layout in the group box using:
    Qt Code:
    1. layout->addWidget(RadioButton1, 0, Qt::AlignHCenter);
    To copy to clipboard, switch view to plain text mode 
    so they are centered in the group box. I have also made the groupbox title to be centered.
    Unfortunately, it appears that the radio button AND its corresponding text are centered and this makes them to be not properly formated vertically when the button texts are of different string lengths. I had to add some empty spaces after the text in order to adjust its size so it is aligned vertically with other buttons, but this seems to be very inconvenient.
    Also the the group box does not get centered and the borders not shown.
    I'm using Ubuntu 11.04; on Windows the borders are shown with the title centered.

    Can anyone help me with the problems I am having.

  2. #2
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

  3. The following user says thank you to Gokulnathvc for this useful post:

    manaila (16th February 2012)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QGroupBox formatting

    It sounds like what you want is the left-aligned radio buttons to be centred inside the group box. You can do that using a horizontal layout containing three things:
    • An expanding horizontal spacer
    • A vertical layout containing the radio buttons (left aligned)
    • An expanding horizontal spacer

    Like this:
    Qt Code:
    1. QGroupBox *groupBox = new QGroupBox("Group", this);
    2. groupBox->setAlignment(Qt::AlignHCenter); // title alignment only
    3.  
    4. QRadioButton *rb1 = new QRadioButton("Radio", this);
    5. QRadioButton *rb2 = new QRadioButton("Another radio", this);
    6.  
    7. QVBoxLayout *vLayout = new QVBoxLayout;
    8. vLayout->addWidget(rb1);
    9. vLayout->addWidget(rb2);
    10.  
    11. QHBoxLayout *hLayout = new QHBoxLayout;
    12. hLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding) );
    13. hLayout->addLayout(vLayout);
    14. hLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding) );
    15.  
    16. groupBox->setLayout(hLayout);
    To copy to clipboard, switch view to plain text mode 

    Also the the group box does not get centred and the borders not shown.
    Centred in what? Setting the title alignment does not affect the placement of the group box itself. You can use the same technique as above to centre the group box in a containing layout if that is what you mean.

    The absence or otherwise of the group box border is driven by the style in use, which varies from platform to platform by default. You can use style sheets to adjust the appearance of different widgets.

Similar Threads

  1. Formatting QString
    By thefatladysingsopera in forum Newbie
    Replies: 2
    Last Post: 11th September 2011, 17:16
  2. Formatting real in QML
    By petermcg in forum Qt Quick
    Replies: 1
    Last Post: 27th November 2010, 00:24
  3. Formatting a QString
    By icentenee in forum Newbie
    Replies: 9
    Last Post: 1st October 2006, 17:41
  4. QString formatting
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2006, 03:00
  5. QToolBox Formatting
    By cwalsh in forum Newbie
    Replies: 8
    Last Post: 9th January 2006, 23:08

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
  •  
Qt is a trademark of The Qt Company.