PDA

View Full Version : QScrollArea



franco.amato
5th January 2010, 19:40
Hi to all,
I attached a QScrollArea to my class inherited from QWidget so:


/* vertical layout */
m_pVbox = new QVBoxLayout( this );

/* scroll area */
sa = new QScrollArea( this );
sa->setWidgetResizable( true );

/* waveform */
m_pWaveU = new WaveDisplay( this );

sa->setWidget( m_pWaveU );

m_pVbox->addWidget( sa );
..add other widgets..

setLayout(m_pVbox);

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

Lawand
5th January 2010, 19:46
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...

franco.amato
5th January 2010, 22:29
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:



CentralWidget::CentralWidget( QWidget* parent /* = 0 */ )
: QWidget(parent),
m_pVbox( 0 ),
m_pWaveU( 0 ),
m_pWaveD( 0 )
{
/* vertical layout */
m_pVbox = new QVBoxLayout( this );

/* scroll area */
saU = new QScrollArea( this );
saD = new QScrollArea( this );

saU->setWidgetResizable( true );
saD->setWidgetResizable( true );

saU->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
saD->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );

/* waveform */
m_pWaveU = new WaveDisplay( this );
m_pWaveD = new WaveDisplay( this );

saU->setWidget( m_pWaveU );
saD->setWidget( m_pWaveD );
m_pVbox->addWidget( saU );
QScrollBar *scrollBar = saU->horizontalScrollBar();

connect(scrollBar, SIGNAL(sliderMoved(int)), this, SLOT(scrollMoved(int)));

m_pVbox->addSpacing( 15 );

m_pVbox->addWidget( saD );

setLayout(m_pVbox);
}

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

numbat
6th January 2010, 09:47
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.

franco.amato
6th January 2010, 15:50
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

wysota
6th January 2010, 16:48
How did you implement sizeHint() for your widget?

franco.amato
6th January 2010, 17:50
How did you implement sizeHint() for your widget?

Hi,
I didn't implement it. Can you help me?

wysota
6th January 2010, 18:01
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.

franco.amato
6th January 2010, 19:25
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

wysota
6th January 2010, 19:42
What exactly you don't know how to do?

franco.amato
6th January 2010, 20:19
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