QHeaderView: Send the StatusTip events to itself if there is no parent
If there is a parent (typically an itemview) then StatusTip events should be sent to that. However in the case of there not being a parent then the event should be sent to the QHeaderView itself. Task-number: QTBUG-68458 Change-Id: I2a8c11c973210c7adf1bf29443f224f968a357a9 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
a93d29198a
commit
f9b11bcf78
@ -2725,7 +2725,7 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
|
|||||||
statusTip = d->model->headerData(logical, d->orientation, Qt::StatusTipRole).toString();
|
statusTip = d->model->headerData(logical, d->orientation, Qt::StatusTipRole).toString();
|
||||||
if (d->shouldClearStatusTip || !statusTip.isEmpty()) {
|
if (d->shouldClearStatusTip || !statusTip.isEmpty()) {
|
||||||
QStatusTipEvent tip(statusTip);
|
QStatusTipEvent tip(statusTip);
|
||||||
QCoreApplication::sendEvent(d->parent, &tip);
|
QCoreApplication::sendEvent(d->parent ? d->parent : this, &tip);
|
||||||
d->shouldClearStatusTip = !statusTip.isEmpty();
|
d->shouldClearStatusTip = !statusTip.isEmpty();
|
||||||
}
|
}
|
||||||
#endif // !QT_NO_STATUSTIP
|
#endif // !QT_NO_STATUSTIP
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include <qtreewidget.h>
|
#include <qtreewidget.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qscreen.h>
|
#include <qscreen.h>
|
||||||
|
#include <qdesktopwidget.h>
|
||||||
|
|
||||||
typedef QList<int> IntList;
|
typedef QList<int> IntList;
|
||||||
|
|
||||||
@ -243,7 +244,7 @@ private slots:
|
|||||||
void testMinMaxSectionSize_data();
|
void testMinMaxSectionSize_data();
|
||||||
void testMinMaxSectionSize();
|
void testMinMaxSectionSize();
|
||||||
void sizeHintCrash();
|
void sizeHintCrash();
|
||||||
|
void statusTips();
|
||||||
protected:
|
protected:
|
||||||
void setupTestData(bool use_reset_model = false);
|
void setupTestData(bool use_reset_model = false);
|
||||||
void additionalInit();
|
void additionalInit();
|
||||||
@ -269,7 +270,19 @@ public:
|
|||||||
int rowCount(const QModelIndex&) const { return rows; }
|
int rowCount(const QModelIndex&) const { return rows; }
|
||||||
int columnCount(const QModelIndex&) const { return cols; }
|
int columnCount(const QModelIndex&) const { return cols; }
|
||||||
bool isEditable(const QModelIndex &) const { return true; }
|
bool isEditable(const QModelIndex &) const { return true; }
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
|
||||||
|
{
|
||||||
|
if (section < 0 || (role != Qt::DisplayRole && role != Qt::StatusTipRole))
|
||||||
|
return QVariant();
|
||||||
|
const int row = (orientation == Qt::Vertical ? section : 0);
|
||||||
|
const int col = (orientation == Qt::Horizontal ? section : 0);
|
||||||
|
if (orientation == Qt::Vertical && row >= rows)
|
||||||
|
return QVariant();
|
||||||
|
if (orientation == Qt::Horizontal && col >= cols)
|
||||||
|
return QVariant();
|
||||||
|
return QLatin1Char('[') + QString::number(row) + QLatin1Char(',')
|
||||||
|
+ QString::number(col) + QLatin1String(",0] -- Header");
|
||||||
|
}
|
||||||
QVariant data(const QModelIndex &idx, int) const
|
QVariant data(const QModelIndex &idx, int) const
|
||||||
{
|
{
|
||||||
if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) {
|
if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) {
|
||||||
@ -3325,6 +3338,54 @@ void tst_QHeaderView::testMinMaxSectionSize()
|
|||||||
QTRY_COMPARE(header.sectionSize(0), defaultSectionSize);
|
QTRY_COMPARE(header.sectionSize(0), defaultSectionSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StatusTipHeaderView : public QHeaderView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StatusTipHeaderView(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = 0) :
|
||||||
|
QHeaderView(orientation, parent), gotStatusTipEvent(false) {}
|
||||||
|
bool gotStatusTipEvent;
|
||||||
|
QString statusTipText;
|
||||||
|
protected:
|
||||||
|
bool event(QEvent *e)
|
||||||
|
{
|
||||||
|
if (e->type() == QEvent::StatusTip) {
|
||||||
|
gotStatusTipEvent = true;
|
||||||
|
statusTipText = static_cast<QStatusTipEvent *>(e)->tip();
|
||||||
|
}
|
||||||
|
return QHeaderView::event(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_QHeaderView::statusTips()
|
||||||
|
{
|
||||||
|
StatusTipHeaderView headerView;
|
||||||
|
QtTestModel model;
|
||||||
|
model.rows = model.cols = 5;
|
||||||
|
headerView.setModel(&model);
|
||||||
|
headerView.viewport()->setMouseTracking(true);
|
||||||
|
headerView.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
|
||||||
|
QSize(500, 500)));
|
||||||
|
headerView.show();
|
||||||
|
qApp->setActiveWindow(&headerView);
|
||||||
|
QVERIFY(QTest::qWaitForWindowActive(&headerView));
|
||||||
|
|
||||||
|
// Ensure it is moved away first and then moved to the relevant section
|
||||||
|
QTest::mouseMove(QApplication::desktop(),
|
||||||
|
headerView.rect().bottomLeft() + QPoint(20, 20));
|
||||||
|
QPoint centerPoint = QRect(headerView.sectionPosition(0), headerView.y(),
|
||||||
|
headerView.sectionSize(0), headerView.height()).center();
|
||||||
|
QTest::mouseMove(headerView.windowHandle(), centerPoint);
|
||||||
|
QTRY_VERIFY(headerView.gotStatusTipEvent);
|
||||||
|
QCOMPARE(headerView.statusTipText, QLatin1String("[0,0,0] -- Header"));
|
||||||
|
|
||||||
|
headerView.gotStatusTipEvent = false;
|
||||||
|
headerView.statusTipText.clear();
|
||||||
|
centerPoint = QRect(headerView.sectionPosition(1), headerView.y(),
|
||||||
|
headerView.sectionSize(1), headerView.height()).center();
|
||||||
|
QTest::mouseMove(headerView.windowHandle(), centerPoint);
|
||||||
|
QTRY_VERIFY(headerView.gotStatusTipEvent);
|
||||||
|
QCOMPARE(headerView.statusTipText, QLatin1String("[0,1,0] -- Header"));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QHeaderView)
|
QTEST_MAIN(tst_QHeaderView)
|
||||||
#include "tst_qheaderview.moc"
|
#include "tst_qheaderview.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user