Results 1 to 11 of 11

Thread: QScrollArea

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

    Default QScrollArea

    Hi to all,
    I attached a QScrollArea to my class inherited from QWidget so:
    Qt Code:
    1. /* vertical layout */
    2. m_pVbox = new QVBoxLayout( this );
    3.  
    4. /* scroll area */
    5. sa = new QScrollArea( this );
    6. sa->setWidgetResizable( true );
    7.  
    8. /* waveform */
    9. m_pWaveU = new WaveDisplay( this );
    10.  
    11. sa->setWidget( m_pWaveU );
    12.  
    13. m_pVbox->addWidget( sa );
    14. ..add other widgets..
    15.  
    16. setLayout(m_pVbox);
    To copy to clipboard, switch view to plain text mode 

    The scroll area should manage the case where the waveform go out of screen width creating a scrollbar.
    I would know if it's possible to emit a signal when I move the scroll bar.

    Best Regards
    Franco Amato

  2. #2
    Join Date
    Dec 2008
    Location
    Qt Reference Documentation
    Posts
    62
    Thanks
    25
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QScrollArea

    The functions sa->horizontalScrollBar() and sa->verticalScrollBar() return pointers to the area's scrollbars.
    You can then use the valueChanged() signal found in either these scrollbars...
    Last edited by Lawand; 5th January 2010 at 20:00.

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

    Default Re: QScrollArea

    Quote Originally Posted by Lawand View Post
    The functions sa->horizontalScrollBar() and sa->verticalScrollBar() return pointers to the area's scrollbars.
    You can then use the valueChanged() signal found in either these scrollbars...
    It doesn't work. The scrollbar is not shown.
    The code is this:

    Qt Code:
    1. CentralWidget::CentralWidget( QWidget* parent /* = 0 */ )
    2. : QWidget(parent),
    3. m_pVbox( 0 ),
    4. m_pWaveU( 0 ),
    5. m_pWaveD( 0 )
    6. {
    7. /* vertical layout */
    8. m_pVbox = new QVBoxLayout( this );
    9.  
    10. /* scroll area */
    11. saU = new QScrollArea( this );
    12. saD = new QScrollArea( this );
    13.  
    14. saU->setWidgetResizable( true );
    15. saD->setWidgetResizable( true );
    16.  
    17. saU->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    18. saD->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    19.  
    20. /* waveform */
    21. m_pWaveU = new WaveDisplay( this );
    22. m_pWaveD = new WaveDisplay( this );
    23.  
    24. saU->setWidget( m_pWaveU );
    25. saD->setWidget( m_pWaveD );
    26. m_pVbox->addWidget( saU );
    27. QScrollBar *scrollBar = saU->horizontalScrollBar();
    28.  
    29. connect(scrollBar, SIGNAL(sliderMoved(int)), this, SLOT(scrollMoved(int)));
    30.  
    31. m_pVbox->addSpacing( 15 );
    32.  
    33. m_pVbox->addWidget( saD );
    34.  
    35. setLayout(m_pVbox);
    36. }
    To copy to clipboard, switch view to plain text mode 

    where CentralWidget is the central widget of a QMainWindow.
    I don't know where I'm wrong. The scroll bar is not displayed.
    Franco Amato

  4. #4
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QScrollArea

    The pasted code looks alright. I suspect the problem may be with the sizing of your widget. The documentation says:
    When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget is set to a suitable value. If a standard QWidget is used for the child widget, it may be necessary to call QWidget::setMinimumSize() to ensure that the contents of the widget are shown correctly within the scroll area.

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

    Default Re: QScrollArea

    Quote Originally Posted by numbat View Post
    The pasted code looks alright. I suspect the problem may be with the sizing of your widget. The documentation says:
    So what should I do? Call MyWidget::setMinimumSize() ?

    Best Regards
    Franco Amato

  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: QScrollArea

    How did you implement sizeHint() for your widget?
    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
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea

    Quote Originally Posted by wysota View Post
    How did you implement sizeHint() for your widget?
    Hi,
    I didn't implement it. Can you help me?
    Franco Amato

  8. #8
    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: QScrollArea

    Quote Originally Posted by franco.amato View Post
    I didn't implement it.
    Then how should the environment know how big your widget is or wants to be? If you told the scroll area it can resize your widget (setWidgetResizable(true)) then it does. If the sizeHint() is empty (the default) then the widget can be resized as its owner sees fit. You should implement sizeHint() and optionally also minimumSizeHint() and maybe also set proper size policy for it.
    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
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea

    Quote Originally Posted by wysota View Post
    Then how should the environment know how big your widget is or wants to be? If you told the scroll area it can resize your widget (setWidgetResizable(true)) then it does. If the sizeHint() is empty (the default) then the widget can be resized as its owner sees fit. You should implement sizeHint() and optionally also minimumSizeHint() and maybe also set proper size policy for it.
    This is exactly what I'm unable to do until 1 month.
    I wrote lots of post about layout. Unlikely I don't understand it. I need some help from mailing list and I don't get it.
    So I would know you if you can help me with this
    Franco Amato

  10. #10
    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: QScrollArea

    What exactly you don't know how to do?
    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
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea

    Quote Originally Posted by wysota View Post
    What exactly you don't know how to do?
    I'm unablle to layout my widgets, giving to them the sizeHint, I'm unable to say that they can grow in 1 direction and not in another etc.
    I like QT, but I don't know why I can not learn layout concepts nor build a good gui.
    If you want I can send you an image explaining what I exactly would implement

    No problem with the back end
    Franco Amato

Similar Threads

  1. Replies: 2
    Last Post: 10th March 2008, 20:16
  2. QScrollArea
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 13th December 2007, 17:20
  3. QScrollArea
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2007, 10:33
  4. QScrollArea ?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 22:15
  5. QScrollArea
    By merry in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2007, 13:05

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.