Results 1 to 20 of 40

Thread: attach more widgets to a QScrollArea

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: attach more widgets to a QScrollArea

    That's not the way to go, really... Nevertheless, I don't see the problem. Would you care to explain?
    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.


  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    That's not the way to go, really... Nevertheless, I don't see the problem. Would you care to explain?
    Which is the way to go?

    Well the problem is that the widget doesn't fit the scroll area.
    I'm not sure the logic I used is correct ( assign the correct parent of every widget )
    Franco Amato

  3. #3
    Join Date
    Oct 2008
    Location
    Boston
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default Re: attach more widgets to a QScrollArea

    Not sure if this is the ideal way to achieve this sort of behavior... but this seems to work on my end (if I understand you correctly)

    Qt Code:
    1. // set size policy for your WaveDisplay widget to use as much vertical space on its parent as is available
    2. m_WaveDisplay->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    3.  
    4. il->setSpacing(0);
    5. il->addWidget(m_TimeDisplay);
    6. il->addWidget(m_WaveDisplay);
    7.  
    8. QWidget* w = new QWidget();
    9. // you had the widget's vertical size policy set to Fixed, so there's no way it could ever expand vertically, changed to Ignored (same as WaveDisplay)
    10. // w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    11. w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    12. w->setMinimumSize(800, 271); // 271 = 250(m_WaveDisplay) + 20(m_TimeDisplay) + 1
    13. w->setLayout(il);
    14.  
    15. sa->setWidgetResizable(true);
    16. sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    17. sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    18. sa->setWidget(w);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by pezmaster31 View Post
    Not sure if this is the ideal way to achieve this sort of behavior... but this seems to work on my end (if I understand you correctly)

    Qt Code:
    1. // set size policy for your WaveDisplay widget to use as much vertical space on its parent as is available
    2. m_WaveDisplay->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    3.  
    4. il->setSpacing(0);
    5. il->addWidget(m_TimeDisplay);
    6. il->addWidget(m_WaveDisplay);
    7.  
    8. QWidget* w = new QWidget();
    9. // you had the widget's vertical size policy set to Fixed, so there's no way it could ever expand vertically, changed to Ignored (same as WaveDisplay)
    10. // w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    11. w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    12. w->setMinimumSize(800, 271); // 271 = 250(m_WaveDisplay) + 20(m_TimeDisplay) + 1
    13. w->setLayout(il);
    14.  
    15. sa->setWidgetResizable(true);
    16. sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    17. sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    18. sa->setWidget(w);
    To copy to clipboard, switch view to plain text mode 
    Hi now the widget fit the scroill area but I still have some problems.
    1) when I resize the widget ( for example user zoom in ) the widget seems to pulse. It grow and shrank (in the orizontally direction that must be fixed) continuosly every time user press zoom button
    2) The scroll bar is not shown. The widget grow ( in a bad way ) but I can not navigate in it with the scroll bar.

    May be my code of zoom is not correct.
    This is the code
    Qt Code:
    1. // executed when user press zoonin button
    2. void WaveWidget::zoomIn()
    3. {
    4. float f = m_ZoomFactor + 0.12;
    5. qDebug() << "WaveWidget::zoomIn - f: " << f;
    6. m_WaveDisplay->setZoomFactor( f );
    7. }
    To copy to clipboard, switch view to plain text mode 

    And then the code to expand the WaveDisplay

    Qt Code:
    1. /************************************************************************/
    2. /* setZoomFactor */
    3. /************************************************************************/
    4. void WaveDisplay::setZoomFactor( float f )
    5. {
    6. int w, h;
    7.  
    8. w = width() * f;
    9. h = height();
    10.  
    11. setMinimumSize( w, h );
    12. QWidget* p = dynamic_cast<QWidget*>( parent() );
    13. if (p)
    14. resize( p->width(), p->height() );
    15. repaint();
    16. }
    To copy to clipboard, switch view to plain text mode 

    I'm sure my code is wrong but I don't know where...
    The zoom is wrote in very few time and I'm not sure is a correct way to do it.
    The code of the zoom of TimeDisplay is not implemented yet..

    Regards
    Franco Amato

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    I changed the code of the zoom so:
    Qt Code:
    1. /************************************************************************/
    2. /* setZoomFactor */
    3. /************************************************************************/
    4. void WaveDisplay::setZoomFactor( float f )
    5. {
    6. int w, h;
    7.  
    8. w = width() * f;
    9. h = height();
    10.  
    11. setMinimumSize( w, h );
    12. QWidget* p = dynamic_cast<QWidget*>( parent() );
    13. if (p)
    14. {
    15. //resize( p->width(), p->height() );
    16. resize(w, h); // <--------------------------------------------------------CHANGED
    17. }
    18.  
    19. repaint();
    20. }
    To copy to clipboard, switch view to plain text mode 

    And now I don't get the "grow and shrank" effect when I zoom. But the status bar still doesn't appear.
    I can not navigate into the wave.
    Any idea?

    Best
    Last edited by franco.amato; 16th January 2010 at 01:40. Reason: errors in the post
    Franco Amato

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

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by franco.amato View Post
    The zoom is wrote in very few time and I'm not sure is a correct way to do it.
    Defintely not

    You are artificially manipulating the size of each child widget which is not a very good idea. Using graphics view or implementing everything as one widget derived from QAbstractScrollArea would be a much better approach.
    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
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    Defintely not

    You are artificially manipulating the size of each child widget which is not a very good idea. Using graphics view or implementing everything as one widget derived from QAbstractScrollArea would be a much better approach.
    Thank you very much.
    Can you give some line the code just to start the widget derived from QAbstractScrollArea?

    Best
    Franco Amato

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

    Default Re: attach more widgets to a QScrollArea

    I can't give you a complete 10 line sample. I can tell you it is just like any ordinary widget with exception that at each time you only see part of it and the part seen is manipulated using QAbstractScrollArea::scrollContentsBy() that you will need to implement.
    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.


  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    I can't give you a complete 10 line sample. I can tell you it is just like any ordinary widget with exception that at each time you only see part of it and the part seen is manipulated using QAbstractScrollArea::scrollContentsBy() that you will need to implement.
    Why I can not inherits from QScrollArea instead of QAbstractScrollArea?
    Franco Amato

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

    Default Re: attach more widgets to a QScrollArea

    You can but in my opinion this is a bad idea for the functionality you are trying to implement.
    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.


  11. #11
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    You can but in my opinion this is a bad idea for the functionality you are trying to implement.

    Is a bit difficult...and I can not find a valid example
    Franco Amato

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

    Default Re: attach more widgets to a QScrollArea

    What is so difficult in it? As for examples, you have the code of Qt, you also have examples of classes that are derived from classes that are derived from QAbstractScrollArea (like views in Item Views).
    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.


  13. #13
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    What is so difficult in it? As for examples, you have the code of Qt, you also have examples of classes that are derived from classes that are derived from QAbstractScrollArea (like views in Item Views).
    I can not find such example in my Qt 4.6.0 installation
    Franco Amato

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

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by franco.amato View Post
    Which is the way to go?
    Either a completely custom widget derived from QAbstractScrollArea or Graphics View.

    Well the problem is that the widget doesn't fit the scroll area.
    setWidgetResizable(true) would fix the problem.
    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.


  15. #15
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    Either a completely custom widget derived from QAbstractScrollArea or Graphics View.


    setWidgetResizable(true) would fix the problem.
    Hi, I already set it to true. It doesn't solve the problem. I posted above the most important code. If you can give a look you can see that the setWidgetResizable(true) is set to true
    Franco Amato

  16. #16
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: attach more widgets to a QScrollArea

    Quote Originally Posted by wysota View Post
    Either a completely custom widget derived from QAbstractScrollArea or Graphics View.
    I can rewrite it if it's the case. Can you give me some hints on how to do it? As now I inherited from QWidget.
    I wrote WaveWidget : QWidget.
    WaveWidget contains vertically aligned
    1) TimeDisplay : QWidget
    2) WaveDisplay : QWidget

    I would attach a QScrollArea to WaveWidget as I said to allow user zoom without results
    Franco Amato

Similar Threads

  1. Adding widgets to QScrollArea
    By ser_bur in forum Qt Programming
    Replies: 6
    Last Post: 19th August 2013, 10:38
  2. QSharedMemory won't attach
    By MattPhillips in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2009, 15:45
  3. Replies: 2
    Last Post: 10th March 2008, 20:16
  4. QScrollArea With Custom Widgets
    By VireX in forum Qt Programming
    Replies: 30
    Last Post: 22nd April 2007, 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
  •  
Qt is a trademark of The Qt Company.