Results 1 to 4 of 4

Thread: "Autosize" QLabel according to text?

  1. #1
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default "Autosize" QLabel according to text?

    Hi, I have this problem. I have form with QVBoxLayout on it and in this layout i have QLabel and another QWidget with some other elements inside. The problem is, that QLabel and QWidget both take half the size of the form, so I have line of text in QLabel, then much unwanted white space and then QWidget. I don't want to set maximal label size because I use this QLabel to diplay other text in many other places. Is there some way out of this?

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "Autosize" QLabel according to text?

    try to play with sizepolicy

  3. #3
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: "Autosize" QLabel according to text?

    Ok, with setting sizepolicy of QWidget to expanding I forced QLabel to shrink to minimal size. But now I have problem inside QWidget because all elements(labels, combo boxes, input boxes) were accordingly spaced to take all size of QWidget so I have one element, unwanted white space, other element, unwanted white space and so on. I tried to setSpacing(), setAlignment() for QWidget layout with no luck :/

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "Autosize" QLabel according to text?

    remove sizepolicy and try to add a stretch below the layout.
    QVboxLayout *vl = new ....;
    vl->addWidget(label);
    vl->addWidget(widget);
    vl->addStretch();

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 20:21
  2. [SOLVED] QPropertyAnimation "text" property in QLabel
    By AlekseyK in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2010, 19:46
  3. Replies: 4
    Last Post: 5th March 2010, 19:03
  4. Replies: 3
    Last Post: 8th July 2008, 20:37
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

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.