QSplitter: Don't move handle in non-pressed state

Fixes: QTBUG-102249
Pick-to: 6.2 6.3
Change-Id: Ib1d74447e346760d1fc9960e11486e8dc7ea3bc0
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Nodir Temirkhodjaev 2022-04-04 13:43:51 +03:00
parent cd1ac8666c
commit 99f22e3fc8
2 changed files with 34 additions and 10 deletions

View File

@ -289,10 +289,11 @@ bool QSplitterHandle::event(QEvent *event)
void QSplitterHandle::mouseMoveEvent(QMouseEvent *e)
{
Q_D(QSplitterHandle);
if (!(e->buttons() & Qt::LeftButton))
if (!d->pressed)
return;
int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPosition().toPoint()))
- d->mouseOffset;
const int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPosition().toPoint()))
- d->mouseOffset;
if (opaqueResize()) {
moveSplitter(pos);
} else {
@ -319,16 +320,18 @@ void QSplitterHandle::mousePressEvent(QMouseEvent *e)
void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e)
{
Q_D(QSplitterHandle);
if (!opaqueResize() && e->button() == Qt::LeftButton) {
int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPosition().toPoint()))
- d->mouseOffset;
if (!d->pressed)
return;
if (!opaqueResize()) {
const int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPosition().toPoint()))
- d->mouseOffset;
d->s->setRubberBand(-1);
moveSplitter(pos);
}
if (e->button() == Qt::LeftButton) {
d->pressed = false;
update();
}
d->pressed = false;
update();
}
/*!

View File

@ -28,6 +28,8 @@
#include <QTest>
#include <QSignalSpy>
#include <qapplication.h>
#include <qsplitter.h>
#include <qstyle.h>
@ -89,6 +91,7 @@ private slots:
void task169702_sizes();
void taskQTBUG_4101_ensureOneNonCollapsedWidget_data();
void taskQTBUG_4101_ensureOneNonCollapsedWidget();
void taskQTBUG_102249_moveNonPressed();
void setLayout();
void autoAdd();
@ -1026,6 +1029,24 @@ void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget()
QTRY_VERIFY(s.sizes().at(0) > 0);
}
void tst_QSplitter::taskQTBUG_102249_moveNonPressed()
{
QSplitter s;
s.setOpaqueResize(true);
s.addWidget(new QWidget());
s.addWidget(new QWidget());
s.show();
QSignalSpy spyMove(&s, &QSplitter::splitterMoved);
QPointF posOutOfWidget = QPointF(30, 30);
QMouseEvent me(QEvent::MouseMove,
posOutOfWidget, s.mapToGlobal(posOutOfWidget),
Qt::NoButton, Qt::MouseButtons(Qt::LeftButton),
Qt::NoModifier);
qApp->sendEvent(s.handle(0), &me);
QCOMPARE(spyMove.count(), 0);
}
void tst_QSplitter::setLayout()
{
QSplitter splitter;