Fixed crash when adding items with spans
This only occurred if the item added was the only item in the last row/column, since then the the internal grid failed to expand (in this case it would always call expand(0, 0), which would not create the extra row/column). [ChangeLog][QtWidgets][QGridLayout] Fixed crash that sometimes happened when adding items with spans that spanned to the bottom/right edge. Task-number: QTBUG-38052 Change-Id: Iba95f6d9d9356b4d1c84c7b93f4af9b4ea0cf714 Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
This commit is contained in:
parent
e67ebe8ba4
commit
3ab6653d97
@ -565,7 +565,7 @@ void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int co
|
|||||||
add(box, row1, col1);
|
add(box, row1, col1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expand(row2 + 1, col2 + 1);
|
expand(qMax(row1, row2) + 1, qMax(col1, col2) + 1);
|
||||||
box->row = row1;
|
box->row = row1;
|
||||||
box->col = col1;
|
box->col = col1;
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ private slots:
|
|||||||
void taskQTBUG_40609_addingWidgetToItsOwnLayout();
|
void taskQTBUG_40609_addingWidgetToItsOwnLayout();
|
||||||
void taskQTBUG_40609_addingLayoutToItself();
|
void taskQTBUG_40609_addingLayoutToItself();
|
||||||
void replaceWidget();
|
void replaceWidget();
|
||||||
|
void dontCrashWhenExtendsToEnd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *testWidget;
|
QWidget *testWidget;
|
||||||
@ -1728,5 +1729,22 @@ void tst_QGridLayout::replaceWidget()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QGridLayout::dontCrashWhenExtendsToEnd()
|
||||||
|
{
|
||||||
|
QWidget window;
|
||||||
|
window.resize(320,200);
|
||||||
|
QWidget parent(&window);
|
||||||
|
QLabel *lbl0 = new QLabel(QLatin1String("lbl0:"));
|
||||||
|
QLabel *lbl1 = new QLabel(QLatin1String("lbl1:"));
|
||||||
|
QPushButton *pb = new QPushButton(QLatin1String("pb1"));
|
||||||
|
QGridLayout *l = new QGridLayout(&parent);
|
||||||
|
l->addWidget(lbl0, 0, 0);
|
||||||
|
l->addWidget(lbl1, 1, 0);
|
||||||
|
// adding an item in the bottom right corner than spans to the end (!)...
|
||||||
|
l->addWidget(pb, 1, 1, -1, -1);
|
||||||
|
// ...should not cause a crash when the items are distributed....
|
||||||
|
l->setGeometry(QRect(0, 0, 200, 50)); // DONT CRASH HERE
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QGridLayout)
|
QTEST_MAIN(tst_QGridLayout)
|
||||||
#include "tst_qgridlayout.moc"
|
#include "tst_qgridlayout.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user