Results 1 to 3 of 3

Thread: Dynamic updates of a QWidget in a QScrollArea

  1. #1
    Join Date
    May 2008
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Dynamic updates of a QWidget in a QScrollArea

    Hi,

    I have a problem with a scroll area for a QWidget when contents get
    changed dynamically, e.g,., added to that QWidget after the setWidget
    call for the QScrollArea. Instead of a lengthy explanation, here is a
    simple example:

    Qt Code:
    1. --- Example.cpp ---
    2. #include <QApplication>
    3. #include <QWidget>
    4. #include <QGridLayout>
    5. #include <QPushButton>
    6. #include <QScrollArea>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11. QWidget *test = new QWidget;
    12. QScrollArea area(0);
    13. area.setWidget(test); // A
    14. QGridLayout gl(test);
    15. gl.setSpacing(0);
    16. gl.setMargin(0);
    17. QPushButton b0("1", test);
    18. gl.addWidget(&b0,0,0);
    19. QPushButton b1("2", test);
    20. gl.addWidget(&b1,0,1);
    21. QPushButton b2("3", test);
    22. gl.addWidget(&b2,1,0);
    23. QPushButton b3("4", test);
    24. gl.addWidget(&b3,1,1);
    25. QPushButton b4("5", test);
    26. gl.addWidget(&b4,2,0);
    27. QPushButton b5("6", test);
    28. gl.addWidget(&b5,2,1);
    29. // area.setWidget(test); // B
    30. area.show();
    31. return app.exec();
    32. }
    33. --- Example.cpp ---
    To copy to clipboard, switch view to plain text mode 

    If I first call setWidget() to put the widget into the QScrollArea and
    then add sub-widgets, e.g., QPushButtons then the QWidget displayed in
    the QScroll area is empty. Everything works fine if I comment out the
    setWidget() call marked "A" and call setWidget() at location"B". However,
    I do have a set up where I want to make changes to the QWidget based
    on user interaction where it is no longer an option to do the
    setWidget() call after changes. Is there a proper way to notify the
    QScrollArea about the fact that the QWidget it contains has changed?

    Thank you for any help

  2. #2
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Dynamic updates of a QWidget in a QScrollArea

    I'm using a qgraphicspixmap in a qgraphicsview and any changes to the pixmap showup when update is called.
    What I would imagine you should do is call update() when you change the QWidget
    -K

  3. #3
    Join Date
    May 2008
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic updates of a QWidget in a QScrollArea

    Hi,

    I succeeded to fix it. It just needs to call area.setWidgetResizable(true) and it now works as expected

    Thanks,
    Plamen

  4. The following user says thank you to plamkata for this useful post:

    Computer Hater (7th August 2011)

Similar Threads

  1. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  2. dynamic qscrollarea
    By hijinks in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2006, 16:48
  3. Dynamic updates to a table widget
    By guiGuy in forum Qt Programming
    Replies: 6
    Last Post: 1st June 2006, 20:24
  4. size issues for custom QWidget in QScrollArea
    By anotheruser in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2006, 14:52
  5. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 22:59

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.