QSplitterHandle: Ensure a minimum grab area
This used to work only for 0- and 1-pixel wide handles. However, and paradoxically, 2- and 3-pixel wide handles would end up with narrower grab areas. We now ensure a 4 or 5 minimum grab area, depending on the handle width parity. The patch also clears the margins and mask if the handle size is increased at some point. Change-Id: I8a16e39fb34b5452d9021dbde8c22bec79df0243 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>bb10
parent
6d1d66a042
commit
2f797f8a91
|
|
@ -241,21 +241,24 @@ void QSplitterHandle::resizeEvent(QResizeEvent *event)
|
|||
{
|
||||
Q_D(const QSplitterHandle);
|
||||
|
||||
// When splitters are only 1 or 0 pixel large we increase the
|
||||
// actual grab area to five pixels
|
||||
// Ensure the actual grab area is at least 4 or 5 pixels
|
||||
const int handleMargin = (5 - d->s->handleWidth()) / 2;
|
||||
|
||||
// Note that QSplitter uses contentsRect for layouting
|
||||
// and ensures that handles are drawn on top of widgets
|
||||
// We simply use the contents margins for draggin and only
|
||||
// paint the mask area
|
||||
bool useTinyMode = (d->s->handleWidth() <= 1);
|
||||
const bool useTinyMode = handleMargin > 0;
|
||||
setAttribute(Qt::WA_MouseNoMask, useTinyMode);
|
||||
if (useTinyMode) {
|
||||
if (orientation() == Qt::Horizontal)
|
||||
setContentsMargins(2, 0, 2, 0);
|
||||
setContentsMargins(handleMargin, 0, handleMargin, 0);
|
||||
else
|
||||
setContentsMargins(0, 2, 0, 2);
|
||||
setContentsMargins(0, handleMargin, 0, handleMargin);
|
||||
setMask(QRegion(contentsRect()));
|
||||
} else {
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
clearMask();
|
||||
}
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ private slots:
|
|||
void replaceWidget();
|
||||
void replaceWidgetWithSplitterChild_data();
|
||||
void replaceWidgetWithSplitterChild();
|
||||
void handleMinimumWidth();
|
||||
|
||||
// task-specific tests below me:
|
||||
void task187373_addAbstractScrollAreas();
|
||||
|
|
@ -820,6 +821,29 @@ void tst_QSplitter::replaceWidgetWithSplitterChild()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QSplitter::handleMinimumWidth()
|
||||
{
|
||||
MyFriendlySplitter split;
|
||||
split.addWidget(new QLabel("Number Wan"));
|
||||
split.addWidget(new QLabel("Number Too"));
|
||||
|
||||
split.show();
|
||||
QTest::qWaitForWindowExposed(&split);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
split.setHandleWidth(i);
|
||||
QTest::qWait(100); // resizing
|
||||
QCOMPARE(split.handle(1)->width(), qMax(4 + (i & 1), i));
|
||||
}
|
||||
|
||||
split.setOrientation(Qt::Vertical);
|
||||
QTest::qWait(100);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
split.setHandleWidth(i);
|
||||
QTest::qWait(100); // resizing
|
||||
QCOMPARE(split.handle(1)->height(), qMax(4 + (i & 1), i));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSplitter::rubberBandNotInSplitter()
|
||||
{
|
||||
MyFriendlySplitter split;
|
||||
|
|
|
|||
Loading…
Reference in New Issue