Results 1 to 5 of 5

Thread: resizing widget inside QScrollArea

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default resizing widget inside QScrollArea

    I have a QScrollArea, and I want the widget inside its viewPort to be resized to the maximum viewport size.
    I have my class Dialog derived from QDialog and I have redefined resizeEvent() method, as follows:
    Qt Code:
    1. #include <QVBoxLayout>
    2.  
    3. Dialog::Dialog(QWidget *parent)
    4. : QDialog(parent)
    5. {
    6. sa = new QScrollArea(this);
    7. sa->setMinimumSize(400,300);
    8. sa->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    9. sa->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );
    10. sa->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );
    11.  
    12. qd = new QDial(this);
    13. qd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    14. sa->setWidget(qd);
    15.  
    16. QVBoxLayout *mainLayout = new QVBoxLayout();
    17. mainLayout->addWidget(sa);
    18.  
    19. setLayout(mainLayout);
    20. }
    21.  
    22. Dialog::~Dialog()
    23. {
    24. delete qd;
    25. delete sa;
    26. delete layout();
    27. }
    28.  
    29. #include <cstdio>
    30.  
    31. void Dialog::resizeEvent ( QResizeEvent * event )
    32. {
    33. qd->resize(sa->viewport()->contentsRect().size());
    34.  
    35. QString str;
    36. str = "sa->viewport()->contentsRect().size() " + QString::number(sa->viewport()->contentsRect().size().width()) + "," + QString::number(sa->viewport()->contentsRect().size().height());
    37. printf("%s\n", str.toAscii().constData());
    38. }
    To copy to clipboard, switch view to plain text mode 

    Once started I expect the QDial to be resized to viewPort size, but I obtain the following:

    And on the console it is wrote:
    sa->viewport()->contentsRect().size() 96,26
    as if the QScrollArea was something like 100x30. But if I try to resize all works, so the piece of code in resizeEvent() works.

    What is wrong? Where is the mistake?
    I also attach the project

    thanks
    Attached Files Attached Files

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. resizing widgets depending on a main widget size
    By luf in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2009, 16:13
  3. Resize widget force layout resizing
    By ^NyAw^ in forum Qt Programming
    Replies: 17
    Last Post: 11th February 2009, 11:27
  4. Custom Widget inside a QVboxLayout
    By nemesis in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2008, 14:55
  5. QScrollArea and resizing
    By rarefluid in forum Qt Programming
    Replies: 8
    Last Post: 22nd July 2007, 14:18

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.