Results 1 to 6 of 6

Thread: adding items in scroll area dynamically

  1. #1
    Join Date
    May 2009
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default adding items in scroll area dynamically

    hi,

    I am adding a groupbox to the scroll area dynamically whenever new connection is made i.e whenever Connection button is clicked, it will create a new connection and a groupbox will be
    created with connection name and is placed on the scroll area.

    My problem the scroll area can display only 10 such group boxes,when my connection exceeds 10, i am unable to view my new connection.

    I wud like to know how to enable the scrollbar when my contents exceeds the scroll area widget size, to view all the item added to scroll area.

    I use QT designer to design my mainwindow and groupbox is created using code(whenever connection clicked event is generated)

    Note:I use verticalscrollbarPolicy as scrollBarAlwaysOn, but still it is not working.

    Pls anyone help me solve this problem.

    Thanks,
    Ezhil

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: adding items in scroll area dynamically

    how are you adding your items? can we see the code?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: adding items in scroll area dynamically

    I guess a lecture of "Size Hints and Layouts" at the QScrollArea docs will provide the solution to you, if not we need some more code - as said.

  4. #4
    Join Date
    May 2009
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: adding items in scroll area dynamically

    Hi,

    Thanks for the reply. Pls find the code below for your reference.


    This is the code for my scroll area in my mainwindow..

    Qt Code:
    1. scrollArea = new QScrollArea(centralwidget);
    2. scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
    3. scrollArea->setGeometry(QRect(1050, 168, 208, 684));
    4. QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    5. sizePolicy.setHorizontalStretch(0);
    6. sizePolicy.setVerticalStretch(0);
    7. scrollArea->setSizePolicy(sizePolicy);
    8. scrollArea->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 255);"));
    9. scrollArea->setFrameShadow(QFrame::Sunken);
    10. scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    11. scrollArea->setWidgetResizable(true);
    12. scrollArea->setAlignment(Qt::AlignJustify|Qt::AlignTop);
    13. scrollAreaWidgetContents = new QWidget();
    14. scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
    15. scrollAreaWidgetContents->setGeometry(QRect(0, 0, 206, 682));
    16.  
    17. Code for placing groupbox in scrollarea..
    18.  
    19. void mainwindow::creatDatabaseBox()
    20. {
    21. static int cCnt = 0;
    22. static int yAxis = 30;
    23. ++cCnt;
    24.  
    25. databaseGrpBox = new QGroupBox(ui.scrollAreaWidgetContents);
    26. databaseGrpBox->setObjectName(QString("dataBaseGrpBox%1").arg(cCnt));
    27. databaseGrpBox->setGeometry(QRect(10,yAxis,174,50));
    28. databaseGrpBox->setTitle("QString("dataBaseGrpBox%1").arg(cCnt)");
    29.  
    30. yAxis = YAxis+55;
    31. }
    To copy to clipboard, switch view to plain text mode 
    This will be called when a connection button is pressed..
    Last edited by jpn; 22nd May 2009 at 16:36. Reason: missing [code] tags

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: adding items in scroll area dynamically

    pls edit your post and add [ CODE ] tags :]
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: adding items in scroll area dynamically

    ok, and I see you have to use layouts :]
    Just add the QVBoxLayout to your scroll area and place widgets in it.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Replies: 5
    Last Post: 17th February 2009, 04:35
  2. abstract scroll area
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 09:15
  3. Dynamically adding tabs
    By larry104 in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2006, 20:27
  4. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 20:04
  5. QRubberBand painting in the scroll area widget
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2006, 16:48

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.