Results 1 to 3 of 3

Thread: Another thead about QScrollArea

  1. #1
    Join Date
    Nov 2006
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Another thead about QScrollArea

    Hi.

    Here is standard test code for QScrollArea and standard task is to scroll down.

    And QScrollArea don't scroll down. Just to the last but one element.

    I try to find what is the maximum value for ScrollArea->verticalScrollBar() and found that it is less than real.

    Where I am wrong? Help please! And how to scroll down to new element.
    Qt Code:
    1. int Step=0;
    2.  
    3. TestWidget::TestWidget():QWidget()
    4. {
    5. QVBoxLayout *InterfaceLayout=new QVBoxLayout(this);
    6.  
    7. ScrollArea=new QScrollArea(this);
    8. ScrollArea->setWidgetResizable(true);
    9. ScrollArea->verticalScrollBar()->setMaximum(100);
    10. InterfaceLayout->addWidget(ScrollArea);
    11. connect(ScrollArea->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sliderMove(int)));
    12.  
    13. ScrollWidget=new QWidget(this);
    14. ScrollWidgetLayout=new QVBoxLayout(ScrollWidget);
    15. ScrollWidgetLayout->setSpacing(0);
    16. ScrollWidgetLayout->setMargin(0);
    17. ScrollArea->setWidget(ScrollWidget);
    18.  
    19.  
    20. NewButton=new QPushButton("new", this);
    21. InterfaceLayout->addWidget(NewButton);
    22. connect(NewButton, SIGNAL(clicked()), this, SLOT(newWidget()));
    23.  
    24. resize(200, 300);
    25. }
    26.  
    27. void TestWidget::newWidget()
    28. {
    29. Step++;
    30.  
    31. QPushButton *nButton=new QPushButton(QString::number(Step), this);
    32. nButton->setMinimumHeight(50);
    33. ScrollWidgetLayout->addWidget(nButton);
    34. nButton->show();
    35.  
    36. // ScrollArea->verticalScrollBar()->setValue(ScrollArea->verticalScrollBar()->maximum()+70);
    37.  
    38. qDebug()<<"maximum scroll"<<ScrollArea->verticalScrollBar()->maximum();
    39.  
    40. ScrollArea->ensureWidgetVisible(nButton);
    41. }
    42.  
    43. void TestWidget::sliderMove(int)
    44. {
    45. qDebug()<<"Real value is"<<ScrollArea->verticalScrollBar()->value();
    46.  
    47. }
    To copy to clipboard, switch view to plain text mode 

    And QScrollArea don't scroll down. Just to the last but one element.
    I try to find what is the maximum value for ScrollArea->verticalScrollBar() and found that it is less than real.

    Where I am wrong? Help please! And how to scroll down to new element.

    Thanks a lot
    Last edited by kalpa; 26th November 2009 at 15:34.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Another thead about QScrollArea

    i dont understand your code much but one thing i can say that.. if you use QScrollArea then never touch the scrollBars max and min value.. that is. dont set max and min of scrollbar... the scrollarea will take care of it.

  3. #3
    Join Date
    Nov 2006
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Another thead about QScrollArea

    I found only one way to scroll down the QScrollArea
    Qt Code:
    1. ScrollArea->verticalScrollBar()->setRange(0, widgetSize.height());
    2. ScrollArea->verticalScrollBar()->setValue(ScrollArea->verticalScrollBar()->maximum());
    To copy to clipboard, switch view to plain text mode 
    And this solution using scrollbar.
    If you know native way to scroll down, just show me.


    And there in nothing understandably in my code.

    Thanks a lot.

Similar Threads

  1. several questions about QScrollArea
    By Sheng in forum Qt Programming
    Replies: 1
    Last Post: 4th June 2009, 15:59
  2. Replies: 1
    Last Post: 13th September 2008, 11:00
  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.