#include <qsplitter.h>
Inheritance diagram for QSplitterHandle:


QSplitterHandle is typically what people think about when they think about a splitter. It is the handle that is used to resize the widgets.
A typical developer using QSplitter will never have to worry about QSplitterHandle. It is provided for developers who want splitter handles that provide extra features, such as popup menus.
The typical way one would create splitter handles is to subclass QSplitter then reimplement QSplitter::createHandle() to instantiate the custom splitter handle. For example, a minimum QSplitter subclass might look like this:
snippets/splitterhandle/splitter.h class Splitter : public QSplitter /^;/
The {QSplitter::}{createHandle()} implementation simply constructs a custom splitter handle, called Splitter in this example:
snippets/splitterhandle/splitter.cpp createHandle() /^/
Information about a given handle can be obtained using functions like orientation() and opaqueResize(), and is retrieved from its parent splitter. Details like these can be used to give custom handles different appearances depending on the splitter's orientation.
The complexity of a custom handle subclass depends on the tasks that it needs to perform. A simple subclass might only provide a paintEvent() implementation:
snippets/splitterhandle/splitter.cpp paintEvent /^/
In this example, a predefined gradient is set up differently depending on the orientation of the handle. QSplitterHandle provides a reasonable size hint for the handle, so the subclass does not need to provide a reimplementation of sizeHint() unless the handle has special size requirements.
Definition at line 138 of file qsplitter.h.
Public Member Functions | |
| QSplitterHandle (Qt::Orientation o, QSplitter *parent) | |
| void | setOrientation (Qt::Orientation o) |
| Qt::Orientation | orientation () const |
| bool | opaqueResize () const |
| QSplitter * | splitter () const |
| QSize | sizeHint () const |
Protected Member Functions | |
| void | paintEvent (QPaintEvent *) |
| void | mouseMoveEvent (QMouseEvent *) |
| void | mousePressEvent (QMouseEvent *) |
| void | mouseReleaseEvent (QMouseEvent *) |
| bool | event (QEvent *) |
| void | moveSplitter (int p) |
| int | closestLegalPosition (int p) |
| QSplitterHandle::QSplitterHandle | ( | Qt::Orientation | orientation, | |
| QSplitter * | parent | |||
| ) |
Creates a QSplitter handle with the given orientation and QSplitter parent.
Definition at line 102 of file qsplitter.cpp.
References d, QObject::parent(), and setOrientation().
00103 : QWidget(*new QSplitterHandlePrivate, parent, 0) 00104 { 00105 Q_D(QSplitterHandle); 00106 d->s = parent; 00107 d->hover = false; 00108 setOrientation(orientation); 00109 }
Here is the call graph for this function:

| void QSplitterHandle::setOrientation | ( | Qt::Orientation | orientation | ) |
Sets the orientation of the splitter handle to orientation. This is usually propogated from the QSplitter.
Definition at line 117 of file qsplitter.cpp.
References d, Qt::Horizontal, QWidget::setCursor(), Qt::SplitHCursor, and Qt::SplitVCursor.
Referenced by QSplitterHandle().
00118 { 00119 Q_D(QSplitterHandle); 00120 d->orient = orientation; 00121 #ifndef QT_NO_CURSOR 00122 setCursor(orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor); 00123 #endif 00124 }
Here is the call graph for this function:

| Qt::Orientation QSplitterHandle::orientation | ( | ) | const |
Returns the handle's orientation. This is usually propagated from the QSplitter.
Definition at line 131 of file qsplitter.cpp.
References d.
Referenced by paintEvent().
00132 { 00133 Q_D(const QSplitterHandle); 00134 return d->orient; 00135 }
| bool QSplitterHandle::opaqueResize | ( | ) | const |
Returns true if widgets are resized dynamically (opaquely), otherwise returns false. This value is controlled by the QSplitter.
Definition at line 145 of file qsplitter.cpp.
References d.
Referenced by mouseMoveEvent(), and mouseReleaseEvent().
00146 { 00147 Q_D(const QSplitterHandle); 00148 return d->s->opaqueResize(); 00149 }
| QSplitter * QSplitterHandle::splitter | ( | ) | const |
Returns the splitter associated with this splitter handle.
Definition at line 157 of file qsplitter.cpp.
| QSize QSplitterHandle::sizeHint | ( | ) | const [virtual] |
Reimplemented from QWidget.
Definition at line 202 of file qsplitter.cpp.
References QStyle::CT_Splitter, d, QSize::expandedTo(), QApplication::globalStrut(), QStyleOption::init(), QWidget::parentWidget(), QStyle::sizeFromContents(), QStyleOption::state, QStyle::State_None, and QWidget::style().
Referenced by QSplitterLayoutStruct::getHandleSize().
00203 { 00204 Q_D(const QSplitterHandle); 00205 int hw = d->s->handleWidth(); 00206 QStyleOption opt(0); 00207 opt.init(d->s); 00208 opt.state = QStyle::State_None; 00209 return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s) 00210 .expandedTo(QApplication::globalStrut()); 00211 }
Here is the call graph for this function:

| void QSplitterHandle::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 278 of file qsplitter.cpp.
References QStyle::CE_Splitter, d, QStyle::drawControl(), Qt::Horizontal, QWidget::isEnabled(), orientation(), p, QWidget::palette(), QStyleOption::palette, QWidget::parentWidget(), QStyleOption::rect, QWidget::rect(), QStyleOption::state, QStyle::State_Enabled, QStyle::State_Horizontal, QStyle::State_MouseOver, QStyle::State_None, and QWidget::style().
00279 { 00280 Q_D(QSplitterHandle); 00281 QPainter p(this); 00282 QStyleOption opt(0); 00283 opt.rect = rect(); 00284 opt.palette = palette(); 00285 if (orientation() == Qt::Horizontal) 00286 opt.state = QStyle::State_Horizontal; 00287 else 00288 opt.state = QStyle::State_None; 00289 if (d->hover) 00290 opt.state |= QStyle::State_MouseOver; 00291 if (isEnabled()) 00292 opt.state |= QStyle::State_Enabled; 00293 parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s); 00294 }
Here is the call graph for this function:

| void QSplitterHandle::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 237 of file qsplitter.cpp.
References QMouseEvent::buttons(), closestLegalPosition(), d, QMouseEvent::globalPos(), Qt::LeftButton, QWidget::mapFromGlobal(), moveSplitter(), opaqueResize(), QWidget::parentWidget(), and QWidget::pos().
00238 { 00239 Q_D(QSplitterHandle); 00240 if (!(e->buttons() & Qt::LeftButton)) 00241 return; 00242 int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos())) 00243 - d->mouseOffset; 00244 if (opaqueResize()) { 00245 moveSplitter(pos); 00246 } else { 00247 d->s->setRubberBand(closestLegalPosition(pos)); 00248 } 00249 }
Here is the call graph for this function:

| void QSplitterHandle::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 254 of file qsplitter.cpp.
References QMouseEvent::button(), d, Qt::LeftButton, and QMouseEvent::pos().
00255 { 00256 Q_D(QSplitterHandle); 00257 if (e->button() == Qt::LeftButton) 00258 d->mouseOffset = d->pick(e->pos()); 00259 }
Here is the call graph for this function:

| void QSplitterHandle::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 264 of file qsplitter.cpp.
References QMouseEvent::button(), d, QMouseEvent::globalPos(), Qt::LeftButton, QWidget::mapFromGlobal(), moveSplitter(), opaqueResize(), QWidget::parentWidget(), and QWidget::pos().
00265 { 00266 Q_D(QSplitterHandle); 00267 if (!opaqueResize() && e->button() == Qt::LeftButton) { 00268 int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos())) 00269 - d->mouseOffset; 00270 d->s->setRubberBand(-1); 00271 moveSplitter(pos); 00272 } 00273 }
Here is the call graph for this function:

| bool QSplitterHandle::event | ( | QEvent * | event | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 216 of file qsplitter.cpp.
References d, QWidget::event(), QEvent::HoverEnter, QEvent::HoverLeave, and QWidget::update().
00217 { 00218 Q_D(QSplitterHandle); 00219 switch(event->type()) { 00220 case QEvent::HoverEnter: 00221 d->hover = true; 00222 update(); 00223 break; 00224 case QEvent::HoverLeave: 00225 d->hover = false; 00226 update(); 00227 break; 00228 default: 00229 break; 00230 } 00231 return QWidget::event(event); 00232 }
Here is the call graph for this function:

| void QSplitterHandle::moveSplitter | ( | int | pos | ) | [protected] |
Tells the splitter to move this handle to position pos, which is the distance from the left or top edge of the widget.
Note that pos is also measured from the left (or top) for right-to-left languages. This function will map pos to the appropriate position before calling QSplitter::moveSplitter().
Definition at line 172 of file qsplitter.cpp.
References d, and Qt::Horizontal.
Referenced by mouseMoveEvent(), and mouseReleaseEvent().
00173 { 00174 Q_D(QSplitterHandle); 00175 if (d->s->isRightToLeft() && d->orient == Qt::Horizontal) 00176 pos = d->s->contentsRect().width() - pos; 00177 d->s->moveSplitter(pos, d->s->indexOf(this)); 00178 }
| int QSplitterHandle::closestLegalPosition | ( | int | pos | ) | [protected] |
Returns the closest legal position to pos of the splitter handle. The positions are measured from the left or top edge of the splitter, even for right-to-left languages.
Definition at line 188 of file qsplitter.cpp.
References d, Qt::Horizontal, s, and w.
Referenced by mouseMoveEvent().
00189 { 00190 Q_D(QSplitterHandle); 00191 QSplitter *s = d->s; 00192 if (s->isRightToLeft() && d->orient == Qt::Horizontal) { 00193 int w = s->contentsRect().width(); 00194 return w - s->closestLegalPosition(w - pos, s->indexOf(this)); 00195 } 00196 return s->closestLegalPosition(pos, s->indexOf(this)); 00197 }
1.5.1