PDA

View Full Version : Problem with layout



franco.amato
18th December 2009, 17:38
Hi,
I trying to layout my widgets but it doesn't work.

I would create 2 widget with a fixed hight and an expanding width but it doesn't work.
I create them so:


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

/* 2 WAVEFORM DISPLAY */
m_pWaveU = new WaveDisplay( this );
m_pWaveU->setGeometry(0, 0,200,150); // I would for this a fixed geometry in height
m_pWaveU->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Minimum );//I WOULD THIS WITH A FIXED HEIGHT AND THAT IT CAN EXPAND HORIZONTALY

m_pWaveD = new WaveDisplay( this );
m_pWaveD->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
mp_vBox->addWidget( m_pWaveU );
mp_vBox->addSpacing( 15 );
mp_vBox->addWidget( m_pWaveD );
setLayout(mp_vBox);
}

Where my code is wrong?
Best Regards

method
18th December 2009, 17:42
enum QSizePolicy::Policy

This enum describes the various per-dimension sizing types used when constructing a QSizePolicy.

Constant Value Description
QSizePolicy::Fixed 0 The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
QSizePolicy::Minimum GrowFlag The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint().
QSizePolicy::Maximum ShrinkFlag The sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint().
QSizePolicy::Preferred GrowFlag | ShrinkFlag The sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy).
QSizePolicy::Expanding GrowFlag | ShrinkFlag | ExpandFlag The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
QSizePolicy::MinimumExpanding GrowFlag | ExpandFlag The sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
QSizePolicy::Ignored ShrinkFlag | GrowFlag | IgnoreFlag The sizeHint() is ignored. The widget will get as much space as possible.
See also PolicyFlag, setHorizontalPolicy(), and setVerticalPolicy().

franco.amato
18th December 2009, 19:27
enum QSizePolicy::Policy

This enum describes the various per-dimension sizing types used when constructing a QSizePolicy.

Constant Value Description
QSizePolicy::Fixed 0 The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
QSizePolicy::Minimum GrowFlag The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint().
QSizePolicy::Maximum ShrinkFlag The sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint().
QSizePolicy::Preferred GrowFlag | ShrinkFlag The sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy).
QSizePolicy::Expanding GrowFlag | ShrinkFlag | ExpandFlag The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
QSizePolicy::MinimumExpanding GrowFlag | ExpandFlag The sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
QSizePolicy::Ignored ShrinkFlag | GrowFlag | IgnoreFlag The sizeHint() is ignored. The widget will get as much space as possible.
See also PolicyFlag, setHorizontalPolicy(), and setVerticalPolicy().

Hi I changed the previous code so

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

/* 2 wavwform display */
m_pWaveU = new WaveDisplay( this );
m_pWaveU->setGeometry(10, 10, 200, 150);
m_pWaveU->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );

m_pWaveD = new WaveDisplay( this );
m_pWaveD->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
mp_vBox->addWidget( m_pWaveU );
mp_vBox->addSpacing( 15 );
mp_vBox->addWidget( m_pWaveD );
setLayout(mp_vBox);
}

But now the m_pWaveU is missing, I can not see it in the form.
Where I'm wrong?
Thank you in advance.

franco.amato
18th December 2009, 19:32
And with this last code both widget are missing, I can not see nothing


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

/* 2 wavwform display */
m_pWaveU = new WaveDisplay( this );
m_pWaveU->setGeometry(10, 10, 200, 150);
m_pWaveU->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );

m_pWaveD = new WaveDisplay( this );
m_pWaveD->setGeometry( 10, 160, 200,150);
m_pWaveD->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
mp_vBox->addWidget( m_pWaveU );
mp_vBox->addSpacing( 15 );
mp_vBox->addWidget( m_pWaveD );
setLayout(mp_vBox);
}