From 71ced8e9d2a8cc363a6e8a039e9431ecf8cf9a01 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Wed, 24 Mar 2010 15:23:22 +0100 Subject: Give 1-pixel splitters a larger grab area This is a trick we have applied to Qt Creator for a while and it makes sense to backport this into Qt. Essentially 1-pixel splitters are unusable at the moment. With this fix the actual splitter handle will be 5 pixels wide and slightly overlap neighbouring widgets. The layout code in QSplitter alreadu use the contentsRect to support this behavior. Task-number: QTBUG-9335 Reviewed-by: thierry --- src/gui/widgets/qsplitter.cpp | 32 +++++++++++++++++++++++++++++++- src/gui/widgets/qsplitter.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qsplitter.cpp b/src/gui/widgets/qsplitter.cpp index 597b28b..88b7517 100644 --- a/src/gui/widgets/qsplitter.cpp +++ b/src/gui/widgets/qsplitter.cpp @@ -227,6 +227,33 @@ QSize QSplitterHandle::sizeHint() const /*! \reimp */ +void QSplitterHandle::resizeEvent(QResizeEvent *event) +{ + Q_D(const QSplitterHandle); + + // When splitters are only 1 pixel large we increase the + // actual grab area to five pixels + + // 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); + setAttribute(Qt::WA_MouseNoMask, useTinyMode); + if (useTinyMode) { + if (orientation() == Qt::Horizontal) + setContentsMargins(2, 0, 2, 0); + else + setContentsMargins(0, 2, 0, 2); + setMask(QRegion(contentsRect())); + } + + QWidget::resizeEvent(event); +} + +/*! + \reimp +*/ bool QSplitterHandle::event(QEvent *event) { Q_D(QSplitterHandle); @@ -301,7 +328,7 @@ void QSplitterHandle::paintEvent(QPaintEvent *) Q_D(QSplitterHandle); QPainter p(this); QStyleOption opt(0); - opt.rect = rect(); + opt.rect = contentsRect(); opt.palette = palette(); if (orientation() == Qt::Horizontal) opt.state = QStyle::State_Horizontal; @@ -1662,6 +1689,9 @@ void QSplitter::setSizes(const QList &list) By default, this property contains a value that depends on the user's platform and style preferences. + + If you set handleWidth to 1, the actual grab area will grow to overlap a + few pixels of it's respective widgets. */ int QSplitter::handleWidth() const diff --git a/src/gui/widgets/qsplitter.h b/src/gui/widgets/qsplitter.h index a793f24..c3b304d 100644 --- a/src/gui/widgets/qsplitter.h +++ b/src/gui/widgets/qsplitter.h @@ -172,6 +172,7 @@ protected: void mouseMoveEvent(QMouseEvent *); void mousePressEvent(QMouseEvent *); void mouseReleaseEvent(QMouseEvent *); + void resizeEvent(QResizeEvent *); bool event(QEvent *); void moveSplitter(int p); -- cgit v0.12