Results 1 to 5 of 5

Thread: QScrollArea madness

  1. #1
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QScrollArea madness

    I'm trying to do something which seems really, really simple, but QT is not playing nicely.

    Is is possible in QT to have a QFrame (from QT Designer, so a QDialog parent) inside lives a QScrollArea - into which I add dynamic home-brew widgets arranged as a QVBoxLayout?

    I've read may threads which have dummy QWidgets being instantiated, QFrame bring re-parented size klugdes, etc etc.

    Is there any decent examples of this anywhere or is this the wrong approach.

    Thanks in advance

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScrollArea madness

    Do you want the QFrame to be the scrollable area or contain the scrollable area?

  3. #3
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QScrollArea madness

    The QFrame should contain the scrollable area - I guess it doesn't need to be a QFrame necessarily..

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScrollArea madness

    Not quite sure what you're looking for. Maybe this example will help you out. Here the scroll area is set to the dialog, but you could easily enough set it to a QFrame or any other QWidget.

    Qt Code:
    1. #ifndef SCROLLTEST_H
    2. #define SCROLLTEST_H
    3.  
    4. #include <QtGui>
    5.  
    6. class ScrollTest : public QDialog
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. ScrollTest(QWidget * parent = 0);
    12. virtual ~ScrollTest();
    13. };
    14.  
    15. #endif // SCROLLTEST_H
    16.  
    17. #include "scrolltest.h"
    18.  
    19. ScrollTest::ScrollTest(QWidget * parent) : QDialog(parent)
    20. {
    21. QWidget * scroll_widget = new QWidget();
    22.  
    23. QVBoxLayout * scroll_layout = new QVBoxLayout();
    24. for(int i = 0; i < 25; i++)
    25. {
    26. QPushButton * button = new QPushButton("ScrollTest");
    27. scroll_layout->addWidget(button);
    28. }
    29.  
    30. scroll_widget->setLayout(scroll_layout);
    31.  
    32. QScrollArea * scroll_area = new QScrollArea();
    33. scroll_area->setWidget(scroll_widget);
    34.  
    35. QVBoxLayout * main_layout = new QVBoxLayout();
    36. main_layout->addWidget(scroll_area);
    37.  
    38. setLayout(main_layout);
    39. }
    40.  
    41. ScrollTest::~ScrollTest()
    42. {}
    43.  
    44. #include <QApplication>
    45. #include "scrolltest.h"
    46.  
    47. int main(int argc, char *argv[])
    48. {
    49. QApplication a(argc, argv);
    50. ScrollTest st;
    51. st.show();
    52. return a.exec();
    53. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by JimDaniel; 13th October 2008 at 20:50.

  5. The following user says thank you to JimDaniel for this useful post:

    innerhippy (13th October 2008)

  6. #5
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QScrollArea madness

    Works a treat - many thanks!

Similar Threads

  1. Replies: 1
    Last Post: 13th September 2008, 11:00
  2. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  3. QScrollArea
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2007, 10:33
  4. QScrollArea and resizing
    By rarefluid in forum Qt Programming
    Replies: 8
    Last Post: 22nd July 2007, 14:18
  5. Replies: 2
    Last Post: 8th October 2006, 20:14

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
  •  
Qt is a trademark of The Qt Company.