panicq
27th March 2018, 00:07
Hello,
I'm having trouble to manager two graphics views in a QSplitter. If I comment the line that adds a rect onto the scene, my splitter have good stretchFactors and behave like intended, but as soon as I add my rect, the first view (index 0 in the splitter) gets wider. Even without using the setStretchFactor lines and by hardcoding a size for the scene it dosen't react properly. Any suggestions ?
m_firstView = new QGraphicsView(this);
m_secondView = new QGraphicsView(this);
m_firstScene = new QGraphicsScene(0,0,100,100,m_firstView);
m_secondScene = new QGraphicsScene(m_secondView);
m_firstScene->addRect(0,10,10, 10, QPen(Qt::black), QBrush(Qt::gray));
m_secondView->setScene(m_secondScene);
m_firstView->setScene(m_firstScene);
m_secondView->setAlignment(Qt::AlignTop|Qt::AlignLeft);
m_firstView->setAlignment(Qt::AlignTop|Qt::AlignLeft);
m_horizontalSplitter = new QSplitter(this);
m_horizontalSplitter->addWidget(m_firstView);
m_horizontalSplitter->addWidget(m_secondView);
m_horizontalSplitter->setOrientation(Qt::Horizontal);
m_horizontalSplitter->setStretchFactor(0,1);
m_horizontalSplitter->setStretchFactor(1,5);
this->setWidget(m_horizontalSplitter);
Thank in advance
I'm having trouble to manager two graphics views in a QSplitter. If I comment the line that adds a rect onto the scene, my splitter have good stretchFactors and behave like intended, but as soon as I add my rect, the first view (index 0 in the splitter) gets wider. Even without using the setStretchFactor lines and by hardcoding a size for the scene it dosen't react properly. Any suggestions ?
m_firstView = new QGraphicsView(this);
m_secondView = new QGraphicsView(this);
m_firstScene = new QGraphicsScene(0,0,100,100,m_firstView);
m_secondScene = new QGraphicsScene(m_secondView);
m_firstScene->addRect(0,10,10, 10, QPen(Qt::black), QBrush(Qt::gray));
m_secondView->setScene(m_secondScene);
m_firstView->setScene(m_firstScene);
m_secondView->setAlignment(Qt::AlignTop|Qt::AlignLeft);
m_firstView->setAlignment(Qt::AlignTop|Qt::AlignLeft);
m_horizontalSplitter = new QSplitter(this);
m_horizontalSplitter->addWidget(m_firstView);
m_horizontalSplitter->addWidget(m_secondView);
m_horizontalSplitter->setOrientation(Qt::Horizontal);
m_horizontalSplitter->setStretchFactor(0,1);
m_horizontalSplitter->setStretchFactor(1,5);
this->setWidget(m_horizontalSplitter);
Thank in advance