Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

qt - Reorganize a QGridLayout in derived class

I develop with QT 5.12. To organize one of my application view I create a QWidget class "BasicView". I divide this view with 4 QFrames (A, B, C, D) and I positioned them using a QGridLayout like this:

BasicView::BasicView(Qwidget* parent)
   : QWidget(parent)
{
m_viewLayout = new QGridLayout();
 
// create frames parts 
A = new QFrame(this);
B = new QFrame(this);
C = new QFrame(this);
D = new QFrame(this);
 
m_rowSpan = 4;
m_columnSpan = 5;
 
m_viewLayout->addWidget(A, 0, 0, m_rowSpan, m_columnSpan);
m_viewLayout->addWidget(B, 0, m_columnSpan, m_rowSpan, 1);
m_viewLayout->addWidget(C, m_rowSpan, 0, 1, m_columnSpan);
m_viewLayout->addWidget(D, m_rowSpan, m_columnSpan, 1, 1);
 
...
}

I have in my application a class "DerivedView" derived from the "BasicView". In this class I add a new QFrame "E" in the gridLayout, update the size of QFrame A and B and hide QFrame C and D. I did this:

DerivedView::DerivedView(Qwidget* parent)
   : BasicView(parent)
{
 
// create frames parts 
E = new QFrame(this);
 
C->hide();
D->hide();
 
m_viewLayout->removeWidget(A);
m_viewLayout->removeWidget(B);
m_viewLayout->addWidget(A, 0, 0, m_rowSpan-1, m_columnSpan);
m_viewLayout->addWidget(B, 0, m_columnSpan, m_rowSpan-1, 1);
m_viewLayout->addWidget(E, m_rowSpan-1, 0, -1, -1);
 
...
}

The problem is that the result of the DeriviedView is not what I expected. For example the QFrame A is as high as in the BasicView while I want it to be smaller (m_rowSpan-1). The QFrame E is as high as QFrame C while I want it to be higher: m_viewLayout->addWidget(E, m_rowSpan-1, 0, -1, -1);

In your opinion what is the wrong in my code? and is there a correct method to reorganize the widgets in an existing QGridLayout?

Thank you.

question from:https://stackoverflow.com/questions/65882805/reorganize-a-qgridlayout-in-derived-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...