
Originally Posted by
pezmaster31
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)
// set size policy for your WaveDisplay widget to use as much vertical space on its parent as is available
il->setSpacing(0);
il->addWidget(m_TimeDisplay);
il->addWidget(m_WaveDisplay);
// 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)
// w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
w->setMinimumSize(800, 271); // 271 = 250(m_WaveDisplay) + 20(m_TimeDisplay) + 1
w->setLayout(il);
sa->setWidgetResizable(true);
sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
sa->setWidget(w);
// set size policy for your WaveDisplay widget to use as much vertical space on its parent as is available
m_WaveDisplay->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
QVBoxLayout* il = new QVBoxLayout;
il->setSpacing(0);
il->addWidget(m_TimeDisplay);
il->addWidget(m_WaveDisplay);
QWidget* w = new QWidget();
// 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)
// w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
w->setMinimumSize(800, 271); // 271 = 250(m_WaveDisplay) + 20(m_TimeDisplay) + 1
w->setLayout(il);
QScrollArea* sa = new QScrollArea;
sa->setWidgetResizable(true);
sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
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
// executed when user press zoonin button
void WaveWidget::zoomIn()
{
float f = m_ZoomFactor + 0.12;
qDebug() << "WaveWidget::zoomIn - f: " << f;
m_WaveDisplay->setZoomFactor( f );
}
// executed when user press zoonin button
void WaveWidget::zoomIn()
{
float f = m_ZoomFactor + 0.12;
qDebug() << "WaveWidget::zoomIn - f: " << f;
m_WaveDisplay->setZoomFactor( f );
}
To copy to clipboard, switch view to plain text mode
And then the code to expand the WaveDisplay
/************************************************************************/
/* setZoomFactor */
/************************************************************************/
void WaveDisplay::setZoomFactor( float f )
{
int w, h;
w = width() * f;
h = height();
setMinimumSize( w, h );
QWidget* p
= dynamic_cast<QWidget
*>
( parent
() );
if (p)
resize( p->width(), p->height() );
repaint();
}
/************************************************************************/
/* setZoomFactor */
/************************************************************************/
void WaveDisplay::setZoomFactor( float f )
{
int w, h;
w = width() * f;
h = height();
setMinimumSize( w, h );
QWidget* p = dynamic_cast<QWidget*>( parent() );
if (p)
resize( p->width(), p->height() );
repaint();
}
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
Bookmarks