Results 1 to 2 of 2

Thread: Definitively QScrollArea doesn't want work. I need help.

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

    Default Definitively QScrollArea doesn't want work. I need help.

    Hi, I'm becoming crazy with my customwidget.
    I would write a widget that can grow orizontally and not vertically. ( fixed height and expanding width ) and I would attach a QScrollArea to it.
    Well it don't work nothing.
    My app inherits from QMainWidget and I do all in the centralwidget. ( in the central widget I would have 2 custom widget that's are WaveForm visualizer.

    To test I add only one and it doesn't work.

    Here the code:

    Qt Code:
    1. CentralWidget::CentralWidget( QWidget* parent /* = 0 */ )
    2. : QWidget(parent),
    3. m_pVbox( 0 ),
    4. m_pWaveU( 0 )
    5. {
    6. /* vertical layout */
    7. m_pVbox = new QVBoxLayout( this );
    8.  
    9. /* scroll area */
    10. saU = new QScrollArea( this );
    11.  
    12. saU->setWidgetResizable( true );
    13.  
    14. saU->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    15.  
    16. /* waveform */
    17. m_pWaveU = new WaveDisplay( saU );
    18.  
    19. m_pWaveU->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    20. m_pWaveU->setMinimumSize( QSize(1000, 200) );
    21.  
    22. saU->setWidget( m_pWaveU );
    23.  
    24. m_pVbox->addWidget( saU );
    25. QScrollBar *scrollBar = saU->horizontalScrollBar();
    26. scrollBar->setSliderDown( true );
    27.  
    28. m_pVbox->addWidget( saU );
    29.  
    30. setLayout(m_pVbox);
    31. }
    To copy to clipboard, switch view to plain text mode 

    I have lots of problems with this code:
    1. If I set
      Qt Code:
      To copy to clipboard, switch view to plain text mode 
      for the vertical size the widget is not shown
    2. The scroll bar is only displayed when I resize the widget at the minimum size
    3. If I draw outsize the visible part of the widget I can not see what I displayed. The scrollbar doesn't allow me to see the graph


    And other, if I call resize( w, h ) inside the widget, it's not resized. The width() routine give to me always the same value.
    i'm really confused. Is 1 month that I try to do this work without any success.
    I'll be very happy to get some help from this mailing list.

    Best Regards,
    Franco
    Franco Amato

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Definitively QScrollArea doesn't want work. I need help.

    Quote Originally Posted by franco.amato View Post
    Hi, I'm becoming crazy with my customwidget.
    So I think that your custom widget code would be more interesting to see if it is there what you done wrong.
    Especially how your sizeHint() method looks like?

    EDIT:
    Consider this example:

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. class Widget : public QWidget
    5. {
    6. Q_OBJECT
    7. public:
    8. Widget(QWidget *parent = 0);
    9. QSize sizeHint() const;
    10. void paintEvent(QPaintEvent *pe);
    11. private slots:
    12. void slotClicked();
    13. private:
    14. QPushButton *m_button;
    15. QSize m_size;
    16. };
    17.  
    18. Widget::Widget(QWidget *parent)
    19. : QWidget(parent)
    20. {
    21. m_size = QSize(200, 80);
    22. m_button = new QPushButton("Button", this);
    23. lo->addWidget(m_button);
    24. connect(m_button, SIGNAL(clicked()), this, SLOT(slotClicked()));
    25. }
    26.  
    27. void Widget::paintEvent(QPaintEvent *pe)
    28. {
    29. QWidget::paintEvent(pe);
    30. QPainter p(this);
    31. p.drawRect(QRect(0, 0, m_size.width()-1, m_size.height()-1));
    32. }
    33.  
    34. QSize Widget::sizeHint() const
    35. {
    36. return m_size;
    37. }
    38.  
    39. void Widget::slotClicked()
    40. {
    41. m_size.setWidth(m_size.width() + 100);
    42. updateGeometry();
    43. update();
    44. }
    45.  
    46. int main(int argc, char **argv)
    47. {
    48. QApplication a(argc, argv);
    49. sa.setWidgetResizable(true);
    50. sa.setWidget(new Widget(&sa));
    51. sa.widget()->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    52. sa.show();
    53. return a.exec();
    54. }
    55.  
    56. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    You can experiment with size policy (read the documentation carefully about QSizePolicy::Policy) with reimplementing minimumSizeHint() and so on...
    Last edited by faldzip; 7th January 2010 at 07:55.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Replies: 2
    Last Post: 13th December 2009, 20:27
  2. Replies: 2
    Last Post: 10th March 2008, 20:16
  3. QScrollArea ?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 22:15
  4. QScrollArea
    By merry in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2007, 13:05
  5. QScrollArea::scrollContentsBy does not work
    By Mad Max in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2006, 14: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.