QTreeWidget: fix visualItemRect()
QTreeWidget::visualItemRect() returned an invalid QRect when a column was moved and then hidden (or the other way round). The reason was that the logical index returned by QHeaderView::logicalIndexAt() was again passed to QHeaderView::logicalIndex() to create the QModelIndexes needed for QTreeView::visualRect() Task-number: QTBUG-28733 Change-Id: I8676f21bcab8c05c2260b85d483902f18cbf3e24 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>bb10
parent
a13a0024d6
commit
2dedf75819
|
|
@ -2859,11 +2859,11 @@ QRect QTreeWidget::visualItemRect(const QTreeWidgetItem *item) const
|
|||
Q_D(const QTreeWidget);
|
||||
//the visual rect for an item is across all columns. So we need to determine
|
||||
//what is the first and last column and get their visual index rects
|
||||
QModelIndex base = d->index(item);
|
||||
const QModelIndex base = d->index(item);
|
||||
const int firstVisiblesection = header()->logicalIndexAt(- header()->offset());
|
||||
const int lastVisibleSection = header()->logicalIndexAt(header()->length() - header()->offset() - 1);
|
||||
QModelIndex first = base.sibling(base.row(), header()->logicalIndex(firstVisiblesection));
|
||||
QModelIndex last = base.sibling(base.row(), header()->logicalIndex(lastVisibleSection));
|
||||
const QModelIndex first = base.sibling(base.row(), firstVisiblesection);
|
||||
const QModelIndex last = base.sibling(base.row(), lastVisibleSection);
|
||||
return visualRect(first) | visualRect(last);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ private slots:
|
|||
void taskQTBUG_34717_collapseAtBottom();
|
||||
void task20345_sortChildren();
|
||||
void getMimeDataWithInvalidItem();
|
||||
void testVisualItemRect();
|
||||
|
||||
public slots:
|
||||
void itemSelectionChanged();
|
||||
|
|
@ -3462,5 +3463,34 @@ void tst_QTreeWidget::getMimeDataWithInvalidItem()
|
|||
QVERIFY(!md);
|
||||
}
|
||||
|
||||
// visualItemRect returned a wrong rect when the columns were moved
|
||||
// (-> logical index != visual index). see QTBUG-28733
|
||||
void tst_QTreeWidget::testVisualItemRect()
|
||||
{
|
||||
QTreeWidget tw;
|
||||
tw.setColumnCount(2);
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(&tw);
|
||||
item->setText(0, "text 0");
|
||||
item->setText(1, "text 1");
|
||||
|
||||
static const int sectionSize = 30;
|
||||
tw.header()->setStretchLastSection(false);
|
||||
tw.header()->setMinimumSectionSize(sectionSize);
|
||||
tw.header()->resizeSection(0, sectionSize);
|
||||
tw.header()->resizeSection(1, sectionSize);
|
||||
tw.setRootIsDecorated(false);
|
||||
tw.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&tw));
|
||||
|
||||
QRect r = tw.visualItemRect(item);
|
||||
QCOMPARE(r.width(), sectionSize * 2); // 2 columns
|
||||
tw.header()->moveSection(1, 0);
|
||||
r = tw.visualItemRect(item);
|
||||
QCOMPARE(r.width(), sectionSize * 2); // 2 columns
|
||||
tw.hideColumn(0);
|
||||
r = tw.visualItemRect(item);
|
||||
QCOMPARE(r.width(), sectionSize);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTreeWidget)
|
||||
#include "tst_qtreewidget.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue