Results 1 to 7 of 7

Thread: Dynamic Scrollarea Content

  1. #1
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Dynamic Scrollarea Content

    hi
    I would like to have a scrollarea contains a dynamic count of images...

    I tried to solve it like you see below. But the problem is that the scrollbar never appear...

    My approach is:
    I design with the QT desinger a ScrollArea (scrollArea) with default ScrollBarAsNeeded. Then I at also in the QT Designer a widget to the ScrollArea (named scrollContent).

    Then in the Programm i tried:
    Qt Code:
    1. QVBoxLayout* ScrollBoxLayout = new QVBoxLayout();
    2. ScrollBoxLayout->setSpacing(2);
    3. ScrollBoxLayout->setMargin(2);
    4. ScrollBoxLayout->setAlignment(Qt::AlignTop);
    5. ScrollBoxLayout->setSizeConstraint(QLayout::SetMinimumSize);
    6. ui.scrollArea->setLayout(ScrollBoxLayout);
    To copy to clipboard, switch view to plain text mode 

    and add the images like:
    Qt Code:
    1. for (it=sig.begin(); it!=sig.end(); it++){
    2. //ignore this part
    3. image = QImage((uchar *) it->Image()->imageData, it->Image()->width, it->Image()->height,QImage::Format_RGB888);
    4. image = image.rgbSwapped();
    5.  
    6. //add qlabel to widget in scrollarea
    7. QLabel *img = new QLabel();
    8. ui.scrollArea->layout()->addWidget(img);
    9. img->setPixmap(QPixmap::fromImage(image));
    10. img->repaint();
    11. }
    To copy to clipboard, switch view to plain text mode 

    so the images appears like I wanted row by row... but no scrollbar appears if there are many QLabel objects added...

    thx

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic Scrollarea Content

    Set the widgetResizable property of the scroll area to true.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamic Scrollarea Content

    hmm that is already on true...

    i also set the maximum height in scrollarea but the area grows with the content...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic Scrollarea Content

    This works for me:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QScrollArea scroll;
    6. scroll.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // it's default anyway
    7. QWidget *viewport = new QWidget;
    8. scroll.setWidget(viewport);
    9. scroll.setWidgetResizable(true);
    10. QVBoxLayout *l = new QVBoxLayout(viewport);
    11. for(int i=0;i<50;++i) {
    12. QPushButton *pb = new QPushButton(QString::number(i+1));
    13. l->addWidget(pb);
    14. }
    15. scroll.show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamic Scrollarea Content

    yes this works...

    but in my case I have a mainwindow and on that there is the scrollarea... and I try to add at runtime...
    and I think thats my problem...

    or is there something other wrong??'


    Added after 26 minutes:


    wow now it works!

    the problem was that the scrollarea must have a layout too!!!

    thx
    Last edited by rouge; 13th May 2011 at 16:04.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic Scrollarea Content

    Quote Originally Posted by rouge View Post
    the problem was that the scrollarea must have a layout too!!!
    The problem is the code you provided states the scroll area has a layout. You probably mean the main window needs a layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamic Scrollarea Content

    The problem is the code you provided states the scroll area has a layout. You probably mean the main window needs a layout.
    yes sure I mean the main window

Similar Threads

  1. Replies: 2
    Last Post: 10th February 2011, 09:42
  2. scrollArea
    By skizzik in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2011, 12:55
  3. ItemViews in ScrollArea
    By SElsner in forum Newbie
    Replies: 3
    Last Post: 4th June 2010, 23:59
  4. scrollArea not updating
    By user in forum Qt Programming
    Replies: 9
    Last Post: 3rd October 2007, 08:17
  5. QTreeWidget without the ScrollArea?
    By Paalrammer in forum Newbie
    Replies: 5
    Last Post: 13th February 2007, 19:06

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.