Removes spacing when widget is hidden in QGridLayout
Removes spacing in QGridLayout when the QWidgets inside of the QGridLayout are hidden, by checking if the sibling is empty, thus duplicate spacing can be avoided. Task-number: QTBUG-52357 Change-Id: I45475e7b264f94ef3bec5f9a4b8cbaa1d53ec6dd Reviewed-by: Karim Pinter <karim.pinter@theqtcompany.com> Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
This commit is contained in:
parent
b7ef2510d1
commit
31c6bee4d5
@ -746,12 +746,16 @@ void QGridLayoutPrivate::setupSpacings(QVector<QLayoutStruct> &chain,
|
|||||||
if (orientation == Qt::Vertical) {
|
if (orientation == Qt::Vertical) {
|
||||||
QGridBox *sibling = vReversed ? previousBox : box;
|
QGridBox *sibling = vReversed ? previousBox : box;
|
||||||
if (sibling) {
|
if (sibling) {
|
||||||
|
if (sibling->item()->isEmpty()) {
|
||||||
|
spacing = 0;
|
||||||
|
} else {
|
||||||
QWidget *wid = sibling->item()->widget();
|
QWidget *wid = sibling->item()->widget();
|
||||||
if (wid)
|
if (wid)
|
||||||
spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top());
|
spacing = qMax(spacing, sibling->item()->geometry().top() - wid->geometry().top());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (spacing > chain.at(previousRow).spacing)
|
if (spacing > chain.at(previousRow).spacing)
|
||||||
chain[previousRow].spacing = spacing;
|
chain[previousRow].spacing = spacing;
|
||||||
|
@ -80,6 +80,7 @@ private slots:
|
|||||||
void taskQTBUG_27420_takeAtShouldUnparentLayout();
|
void taskQTBUG_27420_takeAtShouldUnparentLayout();
|
||||||
void taskQTBUG_40609_addingWidgetToItsOwnLayout();
|
void taskQTBUG_40609_addingWidgetToItsOwnLayout();
|
||||||
void taskQTBUG_40609_addingLayoutToItself();
|
void taskQTBUG_40609_addingLayoutToItself();
|
||||||
|
void taskQTBUG_52357_spacingWhenItemIsHidden();
|
||||||
void replaceWidget();
|
void replaceWidget();
|
||||||
void dontCrashWhenExtendsToEnd();
|
void dontCrashWhenExtendsToEnd();
|
||||||
};
|
};
|
||||||
@ -1650,6 +1651,26 @@ void tst_QGridLayout::taskQTBUG_40609_addingLayoutToItself(){
|
|||||||
QCOMPARE(layout.count(), 0);
|
QCOMPARE(layout.count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QGridLayout::taskQTBUG_52357_spacingWhenItemIsHidden()
|
||||||
|
{
|
||||||
|
QWidget widget;
|
||||||
|
setFrameless(&widget);
|
||||||
|
QGridLayout layout(&widget);
|
||||||
|
layout.setMargin(0);
|
||||||
|
layout.setSpacing(5);
|
||||||
|
QPushButton button1;
|
||||||
|
layout.addWidget(&button1, 0, 0);
|
||||||
|
QPushButton button2;
|
||||||
|
layout.addWidget(&button2, 0, 1);
|
||||||
|
QPushButton button3;
|
||||||
|
layout.addWidget(&button3, 0, 2);
|
||||||
|
widget.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
||||||
|
int tempWidth = button1.width() + button2.width() + button3.width() + 2 * layout.spacing();
|
||||||
|
button2.hide();
|
||||||
|
QTRY_COMPARE_WITH_TIMEOUT(tempWidth, button1.width() + button3.width() + layout.spacing(), 1000);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QGridLayout::replaceWidget()
|
void tst_QGridLayout::replaceWidget()
|
||||||
{
|
{
|
||||||
QWidget wdg;
|
QWidget wdg;
|
||||||
|
Loading…
Reference in New Issue
Block a user