Results 1 to 10 of 10

Thread: scrollArea not updating

  1. #1
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question scrollArea not updating

    I hope someone can help me with my scrollArea problem:

    I defined a scroll area and set a tab widget in it:
    Qt Code:
    1. scrollArea_ = new QScrollArea;
    2. setCentralWidget( scrollArea_);
    3. scrollArea_->setWidgetResizable ( true );
    4. scrollArea_->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
    5. scrollArea_->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded
    6. scrollAreaGridLayout_ = new QGridLayout(scrollArea_);
    7. scrollAreaWidget_ = new QWidget();
    8. scrollAreaGridLayout_->addWidget(scrollAreaWidget_, 0, 1, 1, 1);
    9. scrollArea_->setWidget(scrollAreaWidget_);
    10. tabWidget_ = new QTabWidget();
    11. scrollAreaGridLayout2_ = new QGridLayout(scrollAreaWidget_);
    12. scrollAreaGridLayout2_->addWidget(tabWidget_, 0, 1, 1, 1);
    13. tabWidget_->setEnabled(true);
    To copy to clipboard, switch view to plain text mode 

    So far everything is fine. Later in the code I change the tabWidget_ contents (and size) and the scrollArea displays correctly.
    Depending on the user actions this scrollArea_ should display different things.
    So when I change the display:
    Qt Code:
    1. tabWidget_->hide();
    2. newProfile_->show(); // Another QTabWidget()
    3. scrollAreaGridLayout2_->addWidget(newProfile_, 0, 1, 1, 1);
    To copy to clipboard, switch view to plain text mode 

    The scrollArea gets updated with the new size and appropriate scroll bars.

    Problem: my program changes the newProfile_ QabWidget to display other tabs which are bigger but it seems the scrollArea and the scroll bars are not updated and I can't scroll to see the bigger tabs. I tried to get the new size of the tab and resize the QabWidget and the scrollArea but nothing seems to help.
    Qt Code:
    1. newProfile_->hide();
    2. newProfile_->resize( newQWidgetWidth(), newQWidgetHeight() );
    3. newProfile_->updateGeometry();
    4. scrollArea_->resize( newQWidgetWidth(), newQWidgetHeight() );
    5. scrollArea_->updateGeometry();
    6. scrollAreaWidget_->resize( newQWidgetWidth(), newQWidgetHeight() );
    7. scrollAreaWidget_->updateGeometry();
    8. missionProfile_->show();
    9. scrollAreaGridLayout2_->addWidget(newProfile_, 0, 1, 1, 1);
    To copy to clipboard, switch view to plain text mode 

    Can anyone suggest a solution?

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

    Default Re: scrollArea not updating

    Did you apply layouts everywhere? Based on the fact that you use resize() and updateGeometry() I think not. And you should have.

  3. #3
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scrollArea not updating

    I do have layouts everywhere.
    I found a solution to my problem. I don't know if it's the best way, so if there's a better way please let me know. Also an explanation why it works would be helpful.

    My solution was to add another line:
    Qt Code:
    1. newProfile_->resize( newQWidgetWidth(), newQWidgetHeight() );
    2. newProfile_->setMinimumSize( newQWidgetWidth(), newQWidgetHeight() );
    3. newProfile_->updateGeometry();
    To copy to clipboard, switch view to plain text mode 
    and make sure all the tabs I want to display have their minimum size defined.

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

    Default Re: scrollArea not updating

    If you use resize() and updateGeometry then you are not using layouts everywhere...

  5. #5
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scrollArea not updating

    Ok, I removed resize() and updateGeometry() and only left setMinimumSize() and it still works. So I guess I only need this one command.

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

    Default Re: scrollArea not updating

    What kind of widget is "newprofile_"? Is it a custom widget, a basic Qt widget or a complex widget composed of other widgets?

  7. #7
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scrollArea not updating

    newprofile_ is a class that inherits Qwidget. It contains another QWidget X which has buttons and frames. The frames will eventually display a Qwt plot. Its parent is a QMainWindow.
    Depending on user choice, I show/hide X. When X is hidden, another Qwidget Y is shown in its place. Y is also a class that inherits QWidget and I use the same parent (QMainWindow). An instance of Y is created inside newprofile_.
    So the display can change between X and Y but both are on newprofile_ widget.

    Actually, while trying to explain all that, I realised that maybe the parent of Y should be newprofile_ and not QMainWindow. I changed my code and now the layout works without setMinimumSize() and without me having to do anything special.
    Thanks wysota. Sometimes it helps just trying to explain the things I do.

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

    Default Re: scrollArea not updating

    A side note - for switching between X and Y you could use QStackedWidget. It would improve your design a little (as I assume you are creating/showing/hiding those widgets yourself).

    I'm digging the subject, because you were certainly missing a layout or a size hint here somewhere, but it's hard to say where without knowing the details.

  9. #9
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scrollArea not updating

    I only create the widgets once (I have 13 of them) and let the user select from a QTreeWidget which one to show. I need to do it this way since each type of widget can appear multiple times but present different info depending on it's location in the tree and user input.

    I had a look at QStackedWidget. It displays arrows (to move between the widgets), which probably was the reason I chose not to use it and I'm not sure if the size of the scroll area will adjust for different widget sizes if I put them all in the stacked widget or just always show the biggest size.
    Other than that it does seem like a good idea. I think the way I wrote the code is very similar to QStackedWidget just using show/hide instead of signals. I have to finish other parts of the application first but I will make a note to come back to this one and see if it makes a difference.

    I think my original problem stemmed from not having the right parent to all those new widgets. Once that was fixed everything worked well and I didn't have to set anything more.

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

    Default Re: scrollArea not updating

    Quote Originally Posted by user View Post
    I had a look at QStackedWidget. It displays arrows (to move between the widgets), which probably was the reason I chose not to use it and I'm not sure if the size of the scroll area will adjust for different widget sizes if I put them all in the stacked widget or just always show the biggest size.
    The arrows are only in Designer. They are not there in a real application.

Similar Threads

  1. updating database with custom delegate
    By Shaitan in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2007, 11:34
  2. Replies: 5
    Last Post: 16th May 2007, 12:03
  3. Replies: 15
    Last Post: 8th May 2007, 12:46
  4. QTreeWidget without the ScrollArea?
    By Paalrammer in forum Newbie
    Replies: 5
    Last Post: 13th February 2007, 20:06
  5. Problem with QScrollArea updating from 4.0.1 to 4.1.0
    By SkripT in forum Qt Programming
    Replies: 8
    Last Post: 28th January 2006, 23:35

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.