PDA

View Full Version : QGraphicsView size incorrect after adding to QSplitter



qtninja
15th September 2015, 05:36
I'm having a problem adding a QGraphicsView to my QGridLayout.

My grid layout is setup as a 2x2 grid with vertical and horizontal splitters to allow each view to be resized. Originally i had 4 QOpenGLWidget views which worked fine ( see attachment good.png )

But when i add a QGraphicsView to the splitter it doesn't size correctly (see attachment bad.png). The QGraphicsView is shown in the top right hand side of the grid. I was expecting it to take up 1/2 the grid size in the same way as my QOpenGLWidget.

Most likely something minor wrong but can't figure it out. Any advise appreciated.

Here's my grid layout/splitter setup code;




m_editorLayout = new QGridLayout ( editorGridViewParentWidget );
m_editorLayout->setObjectName ( QStringLiteral ( "gridLayout" ) );
QSplitter* verticalSplitter = new QSplitter ( m_stackedWidgetUI.editorGridViewParentWidget );
verticalSplitter->setObjectName ( QStringLiteral ( "verticalSplitter" ) );
verticalSplitter->setAutoFillBackground ( false );
verticalSplitter->setFrameShape ( QFrame::Panel );
verticalSplitter->setFrameShadow ( QFrame::Raised );
verticalSplitter->setMidLineWidth ( 0 );
verticalSplitter->setOrientation ( Qt::Vertical );
verticalSplitter->setOpaqueResize ( false );
m_editorViewTopHorizontalSplitter = new QSplitter ( verticalSplitter );
m_editorViewBottomHorizontalSplitter = new QSplitter ( verticalSplitter );

m_editorViewTopHorizontalSplitter->setObjectName ( QStringLiteral ( "topHorizontalSplitter" ) );
QSizePolicy sizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
sizePolicy.setHorizontalStretch ( 1 );
sizePolicy.setVerticalStretch ( 0 );
sizePolicy.setHeightForWidth ( m_editorViewTopHorizontalSplitter->sizePolicy().hasHeightForWidth() );
m_editorViewTopHorizontalSplitter->setSizePolicy ( sizePolicy );
m_editorViewTopHorizontalSplitter->setStretchFactor ( 0, 1 );
m_editorViewTopHorizontalSplitter->setStretchFactor ( 1, 1 );
m_editorViewTopHorizontalSplitter->setFrameShape ( QFrame::Panel );
m_editorViewTopHorizontalSplitter->setFrameShadow ( QFrame::Raised );
m_editorViewTopHorizontalSplitter->setMidLineWidth ( 0 );
m_editorViewTopHorizontalSplitter->setOrientation ( Qt::Horizontal );
m_editorViewTopHorizontalSplitter->setOpaqueResize ( false );
m_editorViewBottomHorizontalSplitter->setObjectName ( QStringLiteral ( "bottomHorizontalSplitter" ) );
sizePolicy.setHeightForWidth ( m_editorViewBottomHorizontalSplitter->sizePolicy().hasHeightForWidth() );
m_editorViewBottomHorizontalSplitter->setSizePolicy ( sizePolicy );
m_editorViewTopHorizontalSplitter->setStretchFactor ( 0, 1 );
m_editorViewTopHorizontalSplitter->setStretchFactor ( 1, 1 );
m_editorViewBottomHorizontalSplitter->setFrameShape ( QFrame::Panel );
m_editorViewBottomHorizontalSplitter->setFrameShadow ( QFrame::Raised );
m_editorViewBottomHorizontalSplitter->setOrientation ( Qt::Horizontal );
m_editorViewBottomHorizontalSplitter->setOpaqueResize ( false );

// Add the parent QSplitter than holds the other QSplitters to the QGridLayout
m_editorLayout->addWidget ( verticalSplitter, 0, 0, 1, 1 );



To add the widgets to the splitter i simply use;



m_editorViewTopHorizontalSplitter->addWidget ( view1Widget );
m_editorViewTopHorizontalSplitter->addWidget ( view2Widget );
m_editorViewBottomHorizontalSplitter->addWidget ( view3Widget );
m_editorViewBottomHorizontalSplitter->addWidget ( view4Widget );

deepal_de
16th September 2015, 06:22
Did you try setting the size policy of QGraphicsView?
or you can set a minimum size for the QGraphicsView + size policy as Expanding.

note that when you add items to QGraphicsView it will not resize ,but it will add a scroll bar to the view. just like in your image

qtninja
22nd September 2015, 23:34
Thanks for your reply. I have actually tested different size polices and it didn't help.