Results 1 to 4 of 4

Thread: Minimum QGroupBox size

  1. #1
    Join Date
    May 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Minimum QGroupBox size

    I have a QGroupBox that I initially set up with a given title. Through out the program, based on certain user inputs, this QGroupBox gets resized. Sometimes the title of QGroupBox can be slightly long, and sometimes when the QGroupBox is resized to a smaller size the title can get cut off. Can anyone think of a way to set a minimum width on the QGroupBox which would ensure the full title will always be displayed in its entirety?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Minimum QGroupBox size

    After changing the title try a:
    Qt Code:
    1. QFontMetrics fm(group->font());
    2. int minW = fm.width(group->title());
    3. group->setMinimumWidth(minW);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Minimum QGroupBox size

    Thanks for the suggestion Marcel. It doesn't quite seem to work though. I think I was a little unclear in my stating of the problem though. The title is set when the QGroupBox is constructed. It doesn't changed. The only thing about the QGroupBox that changes is its size. Does that change the problem a little bit?

    Here's my attempt to implement the suggested code:
    Qt Code:
    1. ETGroupBox::ETGroupBox(const QString &title, QWidget *parent):QGroupBox(parent){
    2. setTitle(title);
    3. theGrid = new QGridLayout();
    4. setLayout(theGrid);
    5. QFontMetrics fm(this->font());
    6. int minW = fm.width(this->title());
    7. setMinimumWidth(minW);
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Minimum QGroupBox size

    I've tried messing around with the QFontMetrics, but I still can't quite seem to get it. In fact, it seems like for some reason, my QGroupBox won't respect any minimum width I set for it. If I call resize(sizeHint()) on it, it doesn't seem to be respecting the minimum width.
    Last edited by klnusbaum; 19th June 2008 at 17:27.

Similar Threads

  1. Shrink QMainWindow to Minimum Size
    By kloffy in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2008, 17:54
  2. Qt Layout engine not respecting minimum size?
    By Mike in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2007, 13:27
  3. QMenuBar minimum size
    By Angelo Moriconi in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 21:14
  4. Dynamically changing QGroupBox size
    By T4ng10r in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2007, 15:02
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.