<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qrubberband.cpp --> <title>QRubberBand Class | Qt Widgets 5.11</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-module.html">C++ Classes</a></td><td >QRubberBand</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-types">Public Types</a></li> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#protected-functions">Protected Functions</a></li> <li class="level1"><a href="#reimplemented-protected-functions">Reimplemented Protected Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QRubberBand Class</h1> <!-- $$$QRubberBand-brief --> <p>The <a href="qrubberband.html">QRubberBand</a> class provides a rectangle or line that can indicate a selection or a boundary. <a href="#details">More...</a></p> <!-- @@@QRubberBand --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QRubberBand></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += widgets</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qwidget.html">QWidget</a></td></tr></table></div><ul> <li><a href="qrubberband-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-types"></a> <h2 id="public-types">Public Types</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#Shape-enum">Shape</a></b> { Line, Rectangle }</td></tr> </table></div> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#QRubberBand">QRubberBand</a></b>(QRubberBand::Shape <i>s</i>, QWidget *<i>p</i> = nullptr)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#dtor.QRubberBand">~QRubberBand</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#move">move</a></b>(int <i>x</i>, int <i>y</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#move-1">move</a></b>(const QPoint &<i>p</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#resize">resize</a></b>(int <i>width</i>, int <i>height</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#resize-1">resize</a></b>(const QSize &<i>size</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#setGeometry">setGeometry</a></b>(const QRect &<i>rect</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#setGeometry-1">setGeometry</a></b>(int <i>x</i>, int <i>y</i>, int <i>width</i>, int <i>height</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QRubberBand::Shape </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#shape">shape</a></b>() const</td></tr> </table></div> <ul> <li class="fn">214 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li> <li class="fn">34 public functions inherited from <a href="../qtcore/qobject.html#public-functions">QObject</a></li> <li class="fn">14 public functions inherited from <a href="../qtgui/qpaintdevice.html#public-functions">QPaintDevice</a></li> </ul> <a name="protected-functions"></a> <h2 id="protected-functions">Protected Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#initStyleOption">initStyleOption</a></b>(QStyleOptionRubberBand *<i>option</i>) const</td></tr> </table></div> <a name="reimplemented-protected-functions"></a> <h2 id="reimplemented-protected-functions">Reimplemented Protected Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#changeEvent">changeEvent</a></b>(QEvent *<i>e</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#event">event</a></b>(QEvent *<i>e</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#moveEvent">moveEvent</a></b>(<i>QMoveEvent *</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#paintEvent">paintEvent</a></b>(<i>QPaintEvent *</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#resizeEvent">resizeEvent</a></b>(<i>QResizeEvent *</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qrubberband.html#showEvent">showEvent</a></b>(QShowEvent *<i>e</i>) override</td></tr> </table></div> <ul> <li class="fn">35 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li> <li class="fn">9 protected functions inherited from <a href="../qtcore/qobject.html#protected-functions">QObject</a></li> <li class="fn">1 protected function inherited from <a href="../qtgui/qpaintdevice.html#protected-functions">QPaintDevice</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li class="fn">59 properties inherited from <a href="qwidget.html#properties">QWidget</a></li> <li class="fn">1 property inherited from <a href="../qtcore/qobject.html#properties">QObject</a></li> <li class="fn">19 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li> <li class="fn">1 public slot inherited from <a href="../qtcore/qobject.html#public-slots">QObject</a></li> <li class="fn">3 signals inherited from <a href="qwidget.html#signals">QWidget</a></li> <li class="fn">2 signals inherited from <a href="../qtcore/qobject.html#signals">QObject</a></li> <li class="fn">1 public variable inherited from <a href="../qtcore/qobject.html#public-variables">QObject</a></li> <li class="fn">5 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li> <li class="fn">10 static public members inherited from <a href="../qtcore/qobject.html#static-public-members">QObject</a></li> <li class="fn">1 protected slot inherited from <a href="qwidget.html#protected-slots">QWidget</a></li> <li class="fn">2 protected variables inherited from <a href="../qtcore/qobject.html#protected-variables">QObject</a></li> <li class="fn">1 protected type inherited from <a href="../qtgui/qpaintdevice.html#protected-variables">QPaintDevice</a></li> </ul> <a name="details"></a> <!-- $$$QRubberBand-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qrubberband.html">QRubberBand</a> class provides a rectangle or line that can indicate a selection or a boundary.</p> <p>A rubber band is often used to show a new bounding area (as in a <a href="qsplitter.html">QSplitter</a> or a <a href="qdockwidget.html">QDockWidget</a> that is undocking). Historically this has been implemented using a <a href="../qtgui/qpainter.html">QPainter</a> and XOR, but this approach doesn't always work properly since rendering can happen in the window below the rubber band, but before the rubber band has been "erased".</p> <p>You can create a <a href="qrubberband.html">QRubberBand</a> whenever you need to render a rubber band around a given area (or to represent a single line), then call <a href="qrubberband.html#setGeometry">setGeometry</a>(), <a href="qrubberband.html#move">move</a>() or <a href="qrubberband.html#resize">resize</a>() to position and size it. A common pattern is to do this in conjunction with mouse events. For example:</p> <pre class="cpp"> <span class="type">void</span> Widget<span class="operator">::</span>mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) { origin <span class="operator">=</span> event<span class="operator">-</span><span class="operator">></span>pos(); <span class="keyword">if</span> (<span class="operator">!</span>rubberBand) rubberBand <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qrubberband.html#QRubberBand">QRubberBand</a></span>(<span class="type"><a href="qrubberband.html#QRubberBand">QRubberBand</a></span><span class="operator">::</span>Rectangle<span class="operator">,</span> <span class="keyword">this</span>); rubberBand<span class="operator">-</span><span class="operator">></span>setGeometry(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(origin<span class="operator">,</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>())); rubberBand<span class="operator">-</span><span class="operator">></span>show(); } <span class="type">void</span> Widget<span class="operator">::</span>mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) { rubberBand<span class="operator">-</span><span class="operator">></span>setGeometry(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(origin<span class="operator">,</span> event<span class="operator">-</span><span class="operator">></span>pos())<span class="operator">.</span>normalized()); } <span class="type">void</span> Widget<span class="operator">::</span>mouseReleaseEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) { rubberBand<span class="operator">-</span><span class="operator">></span>hide(); <span class="comment">// determine selection, for example using QRect::intersects()</span> <span class="comment">// and QRect::contains().</span> } </pre> <p>If you pass a parent to <a href="qrubberband.html">QRubberBand</a>'s constructor, the rubber band will display only inside its parent, but stays on top of other child widgets. If no parent is passed, <a href="qrubberband.html">QRubberBand</a> will act as a top-level widget.</p> <p>Call <a href="qwidget.html#show">show</a>() to make the rubber band visible; also when the rubber band is not a top-level. Hiding or destroying the widget will make the rubber band disappear. The rubber band can be a <a href="qrubberband.html#Shape-enum">Rectangle</a> or a <a href="qrubberband.html#Shape-enum">Line</a> (vertical or horizontal), depending on the <a href="qrubberband.html#shape">shape</a>() it was given when constructed.</p> </div> <!-- @@@QRubberBand --> <div class="types"> <h2>Member Type Documentation</h2> <!-- $$$Shape$$$Line$$$Rectangle --> <h3 class="fn" id="Shape-enum"><a name="Shape-enum"></a>enum QRubberBand::<span class="name">Shape</span></h3> <p>This enum specifies what shape a <a href="qrubberband.html">QRubberBand</a> should have. This is a drawing hint that is passed down to the style system, and can be interpreted by each <a href="qstyle.html">QStyle</a>.</p> <div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr> <tr><td class="topAlign"><code>QRubberBand::Line</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">A <a href="qrubberband.html">QRubberBand</a> can represent a vertical or horizontal line. Geometry is still given in <a href="qwidget.html#rect-prop">rect</a>() and the line will fill the given geometry on most styles.</td></tr> <tr><td class="topAlign"><code>QRubberBand::Rectangle</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">A <a href="qrubberband.html">QRubberBand</a> can represent a rectangle. Some styles will interpret this as a filled (often semi-transparent) rectangle, or a rectangular outline.</td></tr> </table></div> <!-- @@@Shape --> </div> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QRubberBand[overload1]$$$QRubberBandQRubberBand::ShapeQWidget* --> <h3 class="fn" id="QRubberBand"><a name="QRubberBand"></a>QRubberBand::<span class="name">QRubberBand</span>(<span class="type"><a href="qrubberband.html#Shape-enum">QRubberBand::Shape</a></span> <i>s</i>, <span class="type"><a href="qwidget.html#QWidget">QWidget</a></span> *<i>p</i> = nullptr)</h3> <p>Constructs a rubber band of shape <i>s</i>, with parent <i>p</i>.</p> <p>By default a rectangular rubber band (<i>s</i> is <code>Rectangle</code>) will use a mask, so that a small border of the rectangle is all that is visible. Some styles (e.g., native <a href="../qtdoc/internationalization.html#macos">macOS</a>) will change this and call <a href="qwidget.html#windowOpacity-prop">QWidget::setWindowOpacity</a>() to make a semi-transparent filled selection rectangle.</p> <!-- @@@QRubberBand --> <!-- $$$~QRubberBand[overload1]$$$~QRubberBand --> <h3 class="fn" id="dtor.QRubberBand"><a name="dtor.QRubberBand"></a><code>[virtual] </code>QRubberBand::<span class="name">~QRubberBand</span>()</h3> <p>Destructor.</p> <!-- @@@~QRubberBand --> <!-- $$$changeEvent[overload1]$$$changeEventQEvent* --> <h3 class="fn" id="changeEvent"><a name="changeEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QRubberBand::<span class="name">changeEvent</span>(<span class="type"><a href="../qtcore/qevent.html">QEvent</a></span> *<i>e</i>)</h3> <p>Reimplemented from <a href="qwidget.html#changeEvent">QWidget::changeEvent</a>().</p> <!-- @@@changeEvent --> <!-- $$$event[overload1]$$$eventQEvent* --> <h3 class="fn" id="event"><a name="event"></a><code>[override virtual protected] </code><span class="type">bool</span> QRubberBand::<span class="name">event</span>(<span class="type"><a href="../qtcore/qevent.html">QEvent</a></span> *<i>e</i>)</h3> <p>Reimplemented from <a href="qwidget.html#event">QWidget::event</a>().</p> <!-- @@@event --> <!-- $$$initStyleOption[overload1]$$$initStyleOptionQStyleOptionRubberBand* --> <h3 class="fn" id="initStyleOption"><a name="initStyleOption"></a><code>[protected] </code><span class="type">void</span> QRubberBand::<span class="name">initStyleOption</span>(<span class="type"><a href="qstyleoptionrubberband.html">QStyleOptionRubberBand</a></span> *<i>option</i>) const</h3> <p>Initialize <i>option</i> with the values from this <a href="qrubberband.html">QRubberBand</a>. This method is useful for subclasses when they need a <a href="qstyleoptionrubberband.html">QStyleOptionRubberBand</a>, but don't want to fill in all the information themselves.</p> <p><b>See also </b><a href="qstyleoption.html#initFrom">QStyleOption::initFrom</a>().</p> <!-- @@@initStyleOption --> <!-- $$$move[overload1]$$$moveintint --> <h3 class="fn" id="move"><a name="move"></a><span class="type">void</span> QRubberBand::<span class="name">move</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>)</h3> <p>Moves the rubberband to point (<i>x</i>, <i>y</i>).</p> <p><b>See also </b><a href="qrubberband.html#resize">resize</a>().</p> <!-- @@@move --> <!-- $$$move$$$moveconstQPoint& --> <h3 class="fn" id="move-1"><a name="move-1"></a><span class="type">void</span> QRubberBand::<span class="name">move</span>(const <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> &<i>p</i>)</h3> <p>This is an overloaded function.</p> <p>Moves the rubberband to point <i>p</i>.</p> <p><b>See also </b><a href="qrubberband.html#resize">resize</a>().</p> <!-- @@@move --> <!-- $$$moveEvent[overload1]$$$moveEventQMoveEvent* --> <h3 class="fn" id="moveEvent"><a name="moveEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QRubberBand::<span class="name">moveEvent</span>(<i>QMoveEvent *</i>)</h3> <p>Reimplemented from <a href="qwidget.html#moveEvent">QWidget::moveEvent</a>().</p> <!-- @@@moveEvent --> <!-- $$$paintEvent[overload1]$$$paintEventQPaintEvent* --> <h3 class="fn" id="paintEvent"><a name="paintEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QRubberBand::<span class="name">paintEvent</span>(<i>QPaintEvent *</i>)</h3> <p>Reimplemented from <a href="qwidget.html#paintEvent">QWidget::paintEvent</a>().</p> <!-- @@@paintEvent --> <!-- $$$resize[overload1]$$$resizeintint --> <h3 class="fn" id="resize"><a name="resize"></a><span class="type">void</span> QRubberBand::<span class="name">resize</span>(<span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3> <p>Resizes the rubberband so that its width is <i>width</i>, and its height is <i>height</i>.</p> <p><b>See also </b><a href="qrubberband.html#move">move</a>().</p> <!-- @@@resize --> <!-- $$$resize$$$resizeconstQSize& --> <h3 class="fn" id="resize-1"><a name="resize-1"></a><span class="type">void</span> QRubberBand::<span class="name">resize</span>(const <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> &<i>size</i>)</h3> <p>This is an overloaded function.</p> <p>Resizes the rubberband so that its new size is <i>size</i>.</p> <p><b>See also </b><a href="qrubberband.html#move">move</a>().</p> <!-- @@@resize --> <!-- $$$resizeEvent[overload1]$$$resizeEventQResizeEvent* --> <h3 class="fn" id="resizeEvent"><a name="resizeEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QRubberBand::<span class="name">resizeEvent</span>(<i>QResizeEvent *</i>)</h3> <p>Reimplemented from <a href="qwidget.html#resizeEvent">QWidget::resizeEvent</a>().</p> <!-- @@@resizeEvent --> <!-- $$$setGeometry[overload1]$$$setGeometryconstQRect& --> <h3 class="fn" id="setGeometry"><a name="setGeometry"></a><span class="type">void</span> QRubberBand::<span class="name">setGeometry</span>(const <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> &<i>rect</i>)</h3> <p>Sets the geometry of the rubber band to <i>rect</i>, specified in the coordinate system of its parent widget.</p> <p><b>See also </b><a href="qwidget.html#geometry-prop">QWidget::geometry</a>.</p> <!-- @@@setGeometry --> <!-- $$$setGeometry$$$setGeometryintintintint --> <h3 class="fn" id="setGeometry-1"><a name="setGeometry-1"></a><span class="type">void</span> QRubberBand::<span class="name">setGeometry</span>(<span class="type">int</span> <i>x</i>, <span class="type">int</span> <i>y</i>, <span class="type">int</span> <i>width</i>, <span class="type">int</span> <i>height</i>)</h3> <p>This is an overloaded function.</p> <p>Sets the geometry of the rubberband to the rectangle whose top-left corner lies at the point (<i>x</i>, <i>y</i>), and with dimensions specified by <i>width</i> and <i>height</i>. The geometry is specified in the parent widget's coordinate system.</p> <!-- @@@setGeometry --> <!-- $$$shape[overload1]$$$shape --> <h3 class="fn" id="shape"><a name="shape"></a><span class="type"><a href="qrubberband.html#Shape-enum">QRubberBand::Shape</a></span> QRubberBand::<span class="name">shape</span>() const</h3> <p>Returns the shape of this rubber band. The shape can only be set upon construction.</p> <!-- @@@shape --> <!-- $$$showEvent[overload1]$$$showEventQShowEvent* --> <h3 class="fn" id="showEvent"><a name="showEvent"></a><code>[override virtual protected] </code><span class="type">void</span> QRubberBand::<span class="name">showEvent</span>(<span class="type"><a href="../qtgui/qshowevent.html">QShowEvent</a></span> *<i>e</i>)</h3> <p>Reimplemented from <a href="qwidget.html#showEvent">QWidget::showEvent</a>().</p> <!-- @@@showEvent --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>