Results 1 to 5 of 5

Thread: resizing widget inside QScrollArea

  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

  2. #2
    Join Date
    Jun 2008
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: resizing widget inside QScrollArea

    u are not helping the qdial to resize are u ?
    qd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

  3. #3
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: resizing widget inside QScrollArea

    Quote Originally Posted by manishkyl View Post
    u are not helping the qdial to resize are u ?
    qd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    and u are not tring to resize the dialog manually aren't u?
    Even if the sizePolicy is Fixed I can resize the qdial, infact resizing the dialog manually all works.
    Instead when the application start, the first time the widgets are shown, the qdial is too small, and it seems that is the QScrollArea::viewPort to be very small.
    Please try to compile and take a look at the console.
    If you simply start and close the application without other interaction, you can see on the console
    sa->viewport()->contentsRect().size() 96,26
    then try to start and resize the dialog. What is written on console?

    It seems that the first time I read sa->viewport()->contentsRect().size() the scrollarea is not yet resized to its final size

    thanks

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: resizing widget inside QScrollArea

    Doesn't QScrollArea::widgetResizable do what you want?
    J-P Nurmi

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

    Default Re: resizing widget inside QScrollArea

    Quote Originally Posted by jpn View Post
    Doesn't QScrollArea::widgetResizable do what you want?
    I don't know... the widget need to be resized so as a magnification only horizontally.

    thanks

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.