Results 1 to 2 of 2

Thread: QVBoxLayout vs Qlabel - resizing issue

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QVBoxLayout vs Qlabel - resizing issue

    simple adding lable into QVBoxLayout layout does not resize label .

    Qt Code:
    1. QLabel *label = new QLabel("test");
    2. QVBoxLayout *layout = new QVBoxLayout;
    3. QWidget *widget = new QWidget;
    4. widget->setLayout(layout);
    5. layout->addWidget(label);
    To copy to clipboard, switch view to plain text mode 

    But when I add QTabWidget it resizes just fine.

    I have tried this scenario using Q Designer and works there.

    I have tried changing different sizePolicy of the label and widget, no luck.

    what I am doing wrong ??

  2. #2
    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: QVBoxLayout vs Qlabel - resizing issue

    How are you determining that the label does not get resized?
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QWidget widget;
    9. QVBoxLayout *layout = new QVBoxLayout;
    10. QLabel *label = new QLabel("test");
    11. layout->addWidget(label);
    12. widget.setLayout(layout);
    13.  
    14. qDebug() << widget.size() << label->size();
    15. widget.show();
    16. qDebug() << widget.size() << label->size();
    17. widget.resize(320, 200);
    18. qDebug() << widget.size() << label->size();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    out:
    Qt Code:
    1. QSize(640, 480) QSize(640, 480)
    2. QSize(47, 39) QSize(25, 17)
    3. QSize(320, 200) QSize(298, 178)
    To copy to clipboard, switch view to plain text mode 
    Some layout resizing is not done until the widget is displayed, but the label is resized.
    Last edited by ChrisW67; 11th July 2011 at 00:57.

Similar Threads

  1. QLabel on top of a QGLWidget background issue
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2011, 17:34
  2. Resizing a QLabel with a pimap. Won't shrink!
    By dh7892 in forum Qt Programming
    Replies: 2
    Last Post: 17th September 2010, 17:30
  3. QLabel and Mouse pointer Issue
    By newb in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2010, 11:31
  4. Prevent a QLabel resizing the parent QWidget
    By danc81 in forum Qt Programming
    Replies: 6
    Last Post: 10th November 2009, 20:54
  5. QLabel Stylesheet selector issue.
    By Enygma in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2007, 14:52

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.