Results 1 to 3 of 3

Thread: Scrollbar in scroll area not working

  1. #1
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Question Scrollbar in scroll area not working

    I have a mainwindow of size 480 x 350. The central widget of the main window is a scroll area of dimension 190 x 220. The code for this is as below -

    Qt Code:
    1. scrollArea = new QScrollArea(centralWidget);
    2. scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
    3. scrollArea->setGeometry(QRect(210, 20, 191, 221));
    4. scrollArea->setWidgetResizable(true);
    5. scrollAreaWidgetContents = new QWidget();
    6.  
    7. scrollAreaWidgetContents->setObjectName(
    8. QString::fromUtf8("scrollAreaWidgetContents"));
    9. scrollAreaWidgetContents->setGeometry(QRect(0, 0, 187, 217));
    10. scrollArea->setWidget(scrollAreaWidgetContents);
    11. MainWindow->setCentralWidget(centralWidget);
    To copy to clipboard, switch view to plain text mode 

    I have a QLabel which is a child of the scrollarea. The code for this is as shown -

    Qt Code:
    1. QLabel* tmp = new QLabel(scrollAreaWidgetContents);
    2. tmp->setText("Custom Label");
    3. tmp->setGeometry(QRect( 300,300,60,60));
    4.  
    5. scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    6. scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    To copy to clipboard, switch view to plain text mode 

    So in the application, the scrollarea must show the scroll bars & user must be able to scroll to the qlabel , which will not be in the displayable area.

    But when I run it, the scrollarea does not show the scrollbars & hence its not scrollable. How do i solve this issue? Am I doing something wrong here ?

  2. #2
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Scrollbar in scroll area not working

    The central widget of the main window is a scroll area
    False, at least according to the code shown. The scroll area is in fact a child of the central widget.

    Also, setGeometry() does its work relative to the parent widget, and you are setting the scrollAreaContents' geometry *before* it has a parent, for example.

    All in all, I think you need to very carefully re-evaluate the parent-child hierarchy of your widgets and how it is manipulated in your code. I'm not sure if this makes a difference here, but it may be a good place to start, and certainly couldn't hurt.
    Last edited by Urthas; 28th August 2010 at 02:16.

  3. #3
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Question Re: Scrollbar in scroll area not working

    I have changed my mainwindow constructor as show -

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. QScrollArea *scrollArea;
    8. QWidget *scrollAreaWidgetContents;
    9. scrollArea = new QScrollArea(this);
    10. scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
    11. scrollArea->setGeometry(QRect(210, 20, 191, 221));
    12. scrollArea->setWidgetResizable(true);
    13. scrollAreaWidgetContents = new QWidget();
    14. scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
    15. scrollAreaWidgetContents->setGeometry(QRect(0, 0, 187, 217));
    16. scrollArea->setWidget(scrollAreaWidgetContents);
    17. this->setCentralWidget( scrollArea );
    18.  
    19. QLabel* tmp = new QLabel(scrollArea);
    20. tmp->setText("label");
    21. tmp->setGeometry(QRect(50,50,2000,2000));
    22. tmp->show();
    23.  
    24. scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    25. scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    26. }
    27.  
    28. MainWindow::~MainWindow()
    29. {
    30. delete ui;
    31. }
    To copy to clipboard, switch view to plain text mode 


    Here ui is a designer form created using QtDesigner. The ui file is attached.

    mainwindow.ui

    When i run this application, the label is not shown nor are the scrollbars visible. How should I proceed ?

Similar Threads

  1. Q Scroll Area that scrolls??
    By hakermania in forum Newbie
    Replies: 6
    Last Post: 24th August 2010, 20:48
  2. Replies: 10
    Last Post: 2nd August 2010, 15:07
  3. Scroll Area problem
    By Lodhart in forum Qt Programming
    Replies: 0
    Last Post: 10th October 2009, 14:03
  4. scroll area like QGraphicsItem
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2008, 12:28
  5. abstract scroll area
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 10:15

Tags for this Thread

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.