QScrollView(3qt)
π QScrollView β the manual page, bestie edition β¨
okay so you opened QScrollView(3qt) and it's giving long. buckle up, we're doing this together π«Ά
β¨ NAME β¨
QScrollView β a scrolling area with on-demand scroll bars π
πΈ SYNOPSIS πΈ
#include <qscrollview.h>
Inherits QFrame.
Inherited by QCanvasView, QTable, QGridView, QIconView, QListBox, QListView, and QTextEdit. (yeah she's a whole matriarch, the whole fam runs through her π
)
π Public Members
QScrollView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
~QScrollView ()
enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit }
virtual void setResizePolicy ( ResizePolicy )
ResizePolicy resizePolicy () const
void removeChild ( QWidget * child )
virtual void addChild ( QWidget * child, int x = 0, int y = 0 )
virtual void moveChild ( QWidget * child, int x, int y )
int childX ( QWidget * child )
int childY ( QWidget * child )
bool childIsVisible ( QWidget * child ) (obsolete)
void showChild ( QWidget * child, bool y = TRUE ) (obsolete)
enum ScrollBarMode { Auto, AlwaysOff, AlwaysOn }
ScrollBarMode vScrollBarMode () const
virtual void setVScrollBarMode ( ScrollBarMode )
ScrollBarMode hScrollBarMode () const
virtual void setHScrollBarMode ( ScrollBarMode )
QWidget * cornerWidget () const
virtual void setCornerWidget ( QWidget * corner )
QScrollBar * horizontalScrollBar () const
QScrollBar * verticalScrollBar () const
QWidget * viewport () const
QWidget * clipper () const
int visibleWidth () const
int visibleHeight () const
int contentsWidth () const
int contentsHeight () const
int contentsX () const
int contentsY () const
void updateContents ( int x, int y, int w, int h )
void updateContents ( const QRect & r )
void updateContents ()
void repaintContents ( int x, int y, int w, int h, bool erase = TRUE )
void repaintContents ( const QRect & r, bool erase = TRUE )
void repaintContents ( bool erase = TRUE )
void contentsToViewport ( int x, int y, int & vx, int & vy ) const
void viewportToContents ( int vx, int vy, int & x, int & y ) const
QPoint contentsToViewport ( const QPoint & p ) const
QPoint viewportToContents ( const QPoint & vp ) const
void enableClipper ( bool y )
void setStaticBackground ( bool y )
bool hasStaticBackground () const
QSize viewportSize ( int x, int y ) const
bool isHorizontalSliderPressed ()
bool isVerticalSliderPressed ()
virtual void setDragAutoScroll ( bool b )
bool dragAutoScroll () const
π Public Slots
virtual void resizeContents ( int w, int h )
void scrollBy ( int dx, int dy )
virtual void setContentsPos ( int x, int y )
void ensureVisible ( int x, int y )
void ensureVisible ( int x, int y, int xmargin, int ymargin )
void center ( int x, int y )
void center ( int x, int y, float xmargin, float ymargin )
void updateScrollBars ()
π¦ Signals
void contentsMoving ( int x, int y )
void horizontalSliderPressed ()
void horizontalSliderReleased ()
void verticalSliderPressed ()
void verticalSliderReleased ()
β Properties
int contentsHeightβ the height of the contents area (read only) πint contentsWidthβ the width of the contents area (read only) πint contentsXβ the X coordinate of the contents that are at the left edge of the viewport (read only) πint contentsYβ the Y coordinate of the contents that are at the top edge of the viewport (read only) πbool dragAutoScrollβ whether autoscrolling in drag move events is enabledScrollBarMode hScrollBarModeβ the mode for the horizontal scroll barResizePolicy resizePolicyβ the resize policyScrollBarMode vScrollBarModeβ the mode for the vertical scroll barint visibleHeightβ the vertical amount of the content that is visible (read only) πint visibleWidthβ the horizontal amount of the content that is visible (read only) π
πΈ Protected Members
virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph )
virtual void drawContentsOffset ( QPainter * p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph )
virtual void contentsMousePressEvent ( QMouseEvent * e )
virtual void contentsMouseReleaseEvent ( QMouseEvent * e )
virtual void contentsMouseDoubleClickEvent ( QMouseEvent * e )
virtual void contentsMouseMoveEvent ( QMouseEvent * e )
virtual void contentsDragEnterEvent ( QDragEnterEvent * )
virtual void contentsDragMoveEvent ( QDragMoveEvent * )
virtual void contentsDragLeaveEvent ( QDragLeaveEvent * )
virtual void contentsDropEvent ( QDropEvent * )
virtual void contentsWheelEvent ( QWheelEvent * e )
virtual void contentsContextMenuEvent ( QContextMenuEvent * e )
virtual void viewportPaintEvent ( QPaintEvent * pe )
virtual void viewportResizeEvent ( QResizeEvent * )
virtual void setMargins ( int left, int top, int right, int bottom )
int leftMargin () const
int topMargin () const
int rightMargin () const
int bottomMargin () const
virtual void setHBarGeometry ( QScrollBar & hbar, int x, int y, int w, int h )
virtual void setVBarGeometry ( QScrollBar & vbar, int x, int y, int w, int h )
virtual bool eventFilter ( QObject * obj, QEvent * e )
π«Ά DESCRIPTION π«Ά
The QScrollView widget is literally a scrolling area with on-demand scroll bars. slay.
okay so here's the tea π: QScrollView is a large canvas β potentially bigger than the coordinate system your underlying window system normally supports. and why does that matter? because it's genuinely easy to blow past those limits (e.g. so many web pages are more than 32000 pixels high π). on top of that, a QScrollView can have QWidgets positioned on it that scroll around together with the drawn content. these sub-widgets can also have positions outside the normal coordinate range (but they're still limited in size, so don't get too excited).
to provide content for the widget, you inherit from QScrollView, reimplement drawContents(), and use resizeContents() to set the size of the viewed area. use addChild() and moveChild() to position widgets on the view. periodt. π
and bestie, to actually use QScrollView effectively you need to understand its widget structure in the three styles of use:
- a single large child widget
- a large panning area with some widgets
- a large panning area with many widgets
π Using One Big Widget
<center>
[Image Omitted]
</center>
The first, simplest usage of QScrollView (depicted above) is appropriate for scrolling areas that are never more than about 4000 pixels in either dimension (this is about the maximum reliable size on X11 servers β no cap, that's just the vibe limit). In this usage, you just make one large child in the QScrollView. The child should be a child of the viewport() of the scrollview and be added with addChild():
QScrollView* sv = new QScrollView(...);
QVBox* big_box = new QVBox(sv->viewport());
sv->addChild(big_box);
You can go on to add arbitrary child widgets to the single child in the scrollview as you would with any widget:
QLabel* child1 = new QLabel("CHILD", big_box);
QLabel* child2 = new QLabel("CHILD", big_box);
QLabel* child3 = new QLabel("CHILD", big_box);
...
Here the QScrollView has four children: the viewport(), the verticalScrollBar(), the horizontalScrollBar() and a small cornerWidget(). The viewport() has one child: the big QVBox. The QVBox has the three QLabel objects as child widgets. When the view is scrolled, the QVBox is moved; its children move with it as child widgets normally do. iconic behaviour tbh β¨
π Using a Very Big View with Some Widgets
<center>
[Image Omitted]
</center>
The second usage of QScrollView (depicted above) is appropriate when few, if any, widgets are on a very large scrolling area that is potentially larger than 4000 pixels in either dimension. In this usage you call resizeContents() to set the size of the area and reimplement drawContents() to paint the contents. You may also add some widgets by making them children of the viewport() and adding them with addChild() (this is the same as the process for the single large widget in the previous example):
QScrollView* sv = new QScrollView(...);
QLabel* child1 = new QLabel("CHILD", sv->viewport());
sv->addChild(child1);
QLabel* child2 = new QLabel("CHILD", sv->viewport());
sv->addChild(child2);
QLabel* child3 = new QLabel("CHILD", sv->viewport());
sv->addChild(child3);
Here, the QScrollView has the same four children: the viewport(), the verticalScrollBar(), the horizontalScrollBar() and a small cornerWidget(). The viewport() has the three QLabel objects as child widgets. When the view is scrolled, the scrollview moves the child widgets individually. π§
π Using a Very Big View with Many Widgets
<center>
[Image Omitted]
</center>
The final usage of QScrollView (depicted above) is appropriate when many widgets are on a very large scrolling area that is potentially larger than 4000 pixels in either dimension. In this usage you call resizeContents() to set the size of the area and reimplement drawContents() to paint the contents. You then call enableClipper(TRUE) and add widgets, again by making them children of the viewport(), and adding them with addChild():
QScrollView* sv = new QScrollView(...);
sv->enableClipper(TRUE);
QLabel* child1 = new QLabel("CHILD", sv->viewport());
sv->addChild(child1);
QLabel* child2 = new QLabel("CHILD", sv->viewport());
sv->addChild(child2);
QLabel* child3 = new QLabel("CHILD", sv->viewport());
sv->addChild(child3);
Here, the QScrollView has four children: the clipper() (not the viewport() this time, keep up bestie π), the verticalScrollBar(), the horizontalScrollBar() and a small cornerWidget(). The clipper() has one child: the viewport(). The viewport() has the same three labels as child widgets. When the view is scrolled the viewport() is moved; its children move with it as child widgets normally do.
okay that's the whole shape of her β structure understood, no cap π«Ά more parts coming, don't go anywhere bestie π
β¨ Details Relevant for All Views β¨
okay bestie, general rules time π normally you're gonna reach for the first or third method if you want any child widgets chillin' in the view.
Not me about to let you get this wrong: the widget you actually see in the scrolled area is the viewport() widget, not the QScrollView itself. so like, if you wanna turn mouse tracking on, you'd do viewport()->setMouseTracking(TRUE). don't @ me, that's just how it is π
For drag-and-drop, you'd setAcceptDrops(TRUE) on the QScrollView (because drag-and-drop events propagate to the parent, slay). But to work out the logical position in the view, you'd need to map the drop co-ordinate from being relative to the QScrollView to being relative to the contents β use the function viewportToContents() for that. iykyk πΈ
To handle mouse events on the scrolling area, subclass scrollview as you would subclass other widgets, but rather than reimplementing mousePressEvent(), reimplement contentsMousePressEvent() instead π«Ά The contents specific event handlers provide translated events in the coordinate system of the scrollview. If you reimplement mousePressEvent(), you'll get called only when part of the QScrollView is clicked β and the only such part is the "corner" (if you don't set a cornerWidget()) and the frame. everything else is covered up by the viewport, clipper or scroll bars. literally all of it π
When you construct a QScrollView, some of the widget flags apply to the viewport() instead of being sent to the QWidget constructor for the QScrollView. This applies to WNoAutoErase, WStaticContents, and WPaintClever. See Qt::WidgetFlags for documentation about these flags. Here are some examples:
- An image-manipulation widget would use
WNoAutoErase|WStaticContentsbecause the widget draws all pixels itself, and when its size increases, it only needs a paint event for the new part because the old part remains unchanged. π¨ - A scrolling game widget in which the background scrolls as the characters move might use
WNoAutoErase(in addition toWStaticContents) so that the window system background does not flash in and out during scrolling. π₯ - A word processing widget might use
WNoAutoEraseand repaint itself line by line to get a less-flickery resizing. If the widget is in a mode in which no text justification can take place, it might useWStaticContentstoo, so that it would only get a repaint for the newly visible parts. π
Child widgets may be moved using addChild() or moveChild(). Use childX() and childY() to get the position of a child widget.
A widget may be placed in the corner between the vertical and horizontal scrollbars with setCornerWidget(). You can get access to the scrollbars using horizontalScrollBar() and verticalScrollBar(), and to the viewport with viewport(). The scroll view can be scrolled using scrollBy(), ensureVisible(), setContentsPos() or center().
The visible area is given by visibleWidth() and visibleHeight(), and the contents area by contentsWidth() and contentsHeight(). The contents may be repainted using one of the repaintContents() or updateContents() functions.
Coordinate conversion is provided by contentsToViewport() and viewportToContents(). β¨
The contentsMoving() signal is emitted just before the contents are moved to a new position.
Warning:QScrollViewcurrently does not erase the background when resized, i.e. you must always clear the background manually in scrollview subclasses. This will change in a future version of Qt and we recommend specifying theWNoAutoEraseflag explicitly. bestie please don't forget this one π
[Image Omitted]
[Image Omitted]
See also Abstract Widget Classes.
π Member Type Documentation π
QScrollView::ResizePolicy
This enum type is used to control a QScrollView's reaction to resize events. π
QScrollView::Defaultβ theQScrollViewselects one of the other settings automatically when it has to. In this version of Qt,QScrollViewchanges toManualif you resize the contents withresizeContents()and toAutoOneif a child is added.QScrollView::Manualβ the contents stays the size set byresizeContents().QScrollView::AutoOneβ if there is only one child widget the contents stays the size of that widget. Otherwise the behavior is undefined. πQScrollView::AutoOneFitβ if there is only one child widget the contents stays the size of that widget'ssizeHint(). If the scrollview is resized larger than the child'ssizeHint(), the child will be resized to fit. If there is more than one child, the behavior is undefined. π
QScrollView::ScrollBarMode
This enum type describes the various modes of QScrollView's scroll bars.
QScrollView::AutoβQScrollViewshows a scroll bar when the content is too large to fit and not otherwise. This is the default. πQScrollView::AlwaysOffβQScrollViewnever shows a scroll bar.QScrollView::AlwaysOnβQScrollViewalways shows a scroll bar.
(The modes for the horizontal and vertical scroll bars are independent.) π¦
π₯ MEMBER FUNCTION DOCUMENTATION π₯
QScrollView::QScrollView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
Constructs a QScrollView called name with parent parent and widget flags f.
The widget flags WStaticContents, WNoAutoErase and WPaintClever are propagated to the viewport() widget. The other widget flags are propagated to the parent constructor as usual. β¨
QScrollView::~QScrollView ()
Destroys the QScrollView. Any children added with addChild() will be deleted. π
void QScrollView::addChild ( QWidget * child, int x = 0, int y = 0 ) [virtual]
Inserts the widget, child, into the scrolled area positioned at (x, y). The position defaults to (0, 0). If the child is already in the view, it is just moved.
You may want to call enableClipper(TRUE) if you add a large number of widgets.
Example: scrollview/scrollview.cpp.
int QScrollView::bottomMargin () const [protected]
Returns the bottom margin.
See also setMargins().
void QScrollView::center ( int x, int y ) [slot]
Scrolls the content so that the point (x, y) is in the center of visible area.
Example: scrollview/scrollview.cpp.
void QScrollView::center ( int x, int y, float xmargin, float ymargin ) [slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Scrolls the content so that the point (x, y) is visible with the xmargin and ymargin margins (as fractions of visible the area).
For example:
- Margin
0.0allows (x, y) to be on the edge of the visible area. - Margin
0.5ensures that (x, y) is in middle 50% of the visible area. - Margin
1.0ensures that (x, y) is in the center of the the visible area. π―
bool QScrollView::childIsVisible ( QWidget * child )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. π
Returns TRUE if child is visible. This is equivalent to child->isVisible().
int QScrollView::childX ( QWidget * child )
Returns the X position of the given child widget. Use this rather than QWidget::x() for widgets added to the view.
This function returns 0 if child has not been added to the view.
int QScrollView::childY ( QWidget * child )
Returns the Y position of the given child widget. Use this rather than QWidget::y() for widgets added to the view.
This function returns 0 if child has not been added to the view.
QWidget * QScrollView::clipper () const
Returns the clipper widget. Contents in the scrollview are ultimately clipped to be inside the clipper widget.
You should not need to use this function. π«Ά
See also visibleWidth and visibleHeight.
void QScrollView::contentsContextMenuEvent ( QContextMenuEvent * e ) [virtual protected]
This event handler is called whenever the QScrollView receives a contextMenuEvent() in e: the mouse position is translated to be a point on the contents.
Example: chart/canvasview.cpp.
void QScrollView::contentsDragEnterEvent ( QDragEnterEvent * ) [virtual protected]
This event handler is called whenever the QScrollView receives a dragEnterEvent(): the drag position is translated to be a point on the contents.
Reimplemented in QTable.
void QScrollView::contentsDragLeaveEvent ( QDragLeaveEvent * ) [virtual protected]
This event handler is called whenever the QScrollView receives a dragLeaveEvent(): the drag position is translated to be a point on the contents.
Reimplemented in QTable.
void QScrollView::contentsDragMoveEvent ( QDragMoveEvent * ) [virtual protected]
This event handler is called whenever the QScrollView receives a dragMoveEvent(): the drag position is translated to be a point on the contents.
Reimplemented in QTable.
void QScrollView::contentsDropEvent ( QDropEvent * ) [virtual protected]
This event handler is called whenever the QScrollView receives a dropEvent(): the drop position is translated to be a point on the contents.
Reimplemented in QTable.
int QScrollView::contentsHeight () const
Returns the height of the contents area. See the "contentsHeight" property for details.
void QScrollView::contentsMouseDoubleClickEvent ( QMouseEvent * e ) [virtual protected]
This event handler is called whenever the QScrollView receives a mouseDoubleClickEvent(): the click position in e is translated to be a point on the contents.
The default implementation generates a normal mouse press event.
Reimplemented in QListView.
void QScrollView::contentsMouseMoveEvent ( QMouseEvent * e ) [virtual protected]
This event handler is called whenever the QScrollView receives a mouseMoveEvent(): the mouse position in e is translated to be a point on the contents.
Examples:
Reimplemented in QListView.
void QScrollView::contentsMousePressEvent ( QMouseEvent * e ) [virtual protected]
This event handler is called whenever the QScrollView receives a mousePressEvent(): the press position in e is translated to be a point on the contents.
Examples:
Reimplemented in QListView.
void QScrollView::contentsMouseReleaseEvent ( QMouseEvent * e ) [virtual protected]
This event handler is called whenever the QScrollView receives a mouseReleaseEvent(): the release position in e is translated to be a point on the contents.
Reimplemented in QListView.
void QScrollView::contentsMoving ( int x, int y ) [signal]
This signal is emitted just before the contents are moved to position (x, y).
See also contentsX and contentsY.
void QScrollView::contentsToViewport ( int x, int y, int & vx, int & vy ) const
Translates a point (x, y) in the contents to a point (vx, vy) on the viewport() widget. π¦
QPoint QScrollView::contentsToViewport ( const QPoint & p ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the point p translated to a point on the viewport() widget.
void QScrollView::contentsWheelEvent ( QWheelEvent * e ) [virtual protected]
okay so this one is the mouse-wheel handler π« Whenever your QScrollView gets a wheelEvent(), this gets called with that event in e. The cute lil twist: the mouse position gets translated so it's a point on the contents β not on the viewport, on the actual scrolled-away content. iykyk π
int QScrollView::contentsWidth () const
Hands you back the width of the contents area, bestie. That's literally it. Want the deets? Go peek at the "contentsWidth" property. β¨
int QScrollView::contentsX () const
Returns the X coordinate of the contents that's sitting at the left edge of the viewport. More info lives in the "contentsX" property π
int QScrollView::contentsY () const
Same energy, vertical flavor: returns the Y coordinate of the contents chilling at the top edge of the viewport. Check the "contentsY" property for the full story πΈ
QWidget * QScrollView::cornerWidget () const
Returns the widget living in the corner between the two scroll bars π«Ά
By default? No corner widget exists at all. It's just vibes and empty space.
Example: scrollview/scrollview.cpp.
bool QScrollView::dragAutoScroll () const
Returns TRUE if autoscrolling in drag move events is turned on, otherwise FALSE. The "dragAutoScroll" property has the receipts π₯
void QScrollView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ) [virtual protected]
THIS one is the main character for anyone drawing their own stuff π¨ Reimplement this function if you're viewing a drawing area instead of a widget.
Your job: draw the rectangle (clipx, clipy, clipw, cliph) of the contents using painter p. And heads up β the clip rectangle is in the scrollview's coordinates, not the contents'.
Like, for example:
{
// Fill a 40000 by 50000 rectangle at (100000,150000)
// Calculate the coordinates...
int x1 = 100000, y1 = 150000;
int x2 = x1+40000-1, y2 = y1+50000-1;
// Clip the coordinates so X/Windows will not have problems...
if (x1 < clipx) x1=clipx;
if (y1 < clipy) y1=clipy;
if (x2 > clipx+clipw-1) x2=clipx+clipw-1;
if (y2 > clipy+cliph-1) y2=clipy+cliph-1;
// Paint using the small coordinates...
if ( x2 >= x1 && y2 >= y1 )
p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red);
}
Good news: the clip rectangle and the translation of painter p are already set appropriately for you. No heavy lifting π
Example: qdir/qdir.cpp.
Reimplemented in QCanvasView and QTable.
void QScrollView::drawContentsOffset ( QPainter * p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph ) [virtual protected]
For backward-compatibility only β it's way easier to just use drawContents(QPainter*,int,int,int,int). π«Ά
The default implementation translates the painter appropriately and then calls drawContents(QPainter*,int,int,int,int). Wanna know what all those params (p, offsetx, offsety, clipx, clipy, clipw and cliph) mean? drawContents() has the explanation, go read that.
Reimplemented in QListView.
void QScrollView::enableClipper ( bool y )
When you've got a large number of child widgets in a scrollview β especially if they're all squished close together β the scrolling performance can suffer greatly. π If y is TRUE, the scrollview uses an extra widget to group the child widgets together and things get way smoother.
β οΈ Note that you may only call enableClipper() prior to adding widgets. Do not wait.
For the full discussion, see this class's detailed description π
Example: scrollview/scrollview.cpp.
void QScrollView::ensureVisible ( int x, int y ) [slot]
Scrolls the content so the point (x, y) is visible with at least 50-pixel margins β if possible, otherwise it centers it. β¨
void QScrollView::ensureVisible ( int x, int y, int xmargin, int ymargin ) [slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Scrolls the content so the point (x, y) is visible with at least the xmargin and ymargin margins β if possible, otherwise centered. π
bool QScrollView::eventFilter ( QObject * obj, QEvent * e ) [virtual protected]
This event filter is the little bodyguard that keeps everything in check: it makes sure the scroll bars get updated whenever a single contents widget is resized, shown, hidden or destroyed. It also passes mouse events along to the QScrollView. The event is in e and the object is in obj. π¦
Reimplemented from QObject.
Reimplemented in QListView.
ScrollBarMode QScrollView::hScrollBarMode () const
Returns the mode for the horizontal scroll bar. The "hScrollBarMode" property has all the details π
bool QScrollView::hasStaticBackground () const
Returns TRUE if QScrollView uses a static background, otherwise returns FALSE.
See also setStaticBackground(). π«Ά
QScrollBar * QScrollView::horizontalScrollBar () const
Returns the component horizontal scroll bar. It's made available to allow things like accelerators, autoscrolling, etc. π
It should not be used for other purposes. Respect the scroll bar's boundaries, bestie.
Good news: this function never returns 0. π
void QScrollView::horizontalSliderPressed () [signal]
This signal is emitted whenever the user presses the horizontal slider. β¨
void QScrollView::horizontalSliderReleased () [signal]
This signal is emitted whenever the user releases the horizontal slider. π«
bool QScrollView::isHorizontalSliderPressed ()
Returns TRUE if the horizontal slider is pressed by the user, otherwise returns FALSE.
bool QScrollView::isVerticalSliderPressed ()
Returns TRUE if the vertical slider is pressed by the user, otherwise returns FALSE.
int QScrollView::leftMargin () const [protected]
Returns the left margin.
See also setMargins(). πΈ
void QScrollView::moveChild ( QWidget * child, int x, int y ) [virtual]
Repositions the child widget to (x, y). Fun fact: this function is the same as addChild() π
void QScrollView::removeChild ( QWidget * child )
Removes the child widget from the scrolled area. Note that this happens automatically if the child gets deleted β the scrollview handles it, you don't gotta do anything π«Ά
void QScrollView::repaintContents ( int x, int y, int w, int h, bool erase = TRUE )
Calls repaint() on a rectangle defined by x, y, w, h, translated appropriately. If the rectangle isn't visible, nothing gets repainted. If erase is TRUE, the background gets cleared using the background color. π¨
See also updateContents().
void QScrollView::repaintContents ( const QRect & r, bool erase = TRUE )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Repaints the contents of rectangle r. If erase is TRUE, the background is cleared using the background color.
void QScrollView::repaintContents ( bool erase = TRUE )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Repaints the contents. If erase is TRUE, the background is cleared using the background color. π
void QScrollView::resizeContents ( int w, int h ) [virtual slot]
Sets the size of the contents area to w pixels wide and h pixels high, then updates the viewport accordingly. Slay. β¨
ResizePolicy QScrollView::resizePolicy () const
Returns the resize policy. The "resizePolicy" property has the details π₯
int QScrollView::rightMargin () const [protected]
Returns the right margin.
See also setMargins(). πΈ
void QScrollView::scrollBy ( int dx, int dy ) [slot]
Scrolls the content by dx to the left and dy upwards. π¦
void QScrollView::setContentsPos ( int x, int y ) [virtual slot]
Scrolls the content so that the point (x, y) is in the top-left corner. Main character positioning π
Example: process/process.cpp.
void QScrollView::setCornerWidget ( QWidget * corner ) [virtual]
Sets the widget in the corner between the two scroll bars. π
You'll probably also wanna set at least one of the scroll bar modes to AlwaysOn.
Passing 0 shows no widget in the corner.
Any previous corner widget gets hidden.
You may call setCornerWidget() with the same widget at different times β that's totally fine.
Heads up: all widgets set here will be deleted by theQScrollViewwhen it is destroyed, unless you separately reparent the widget after setting some other corner widget (or0).
Also: any newly set widget should have no current parent.
By default, no corner widget is present.
See also vScrollBarMode and hScrollBarMode.
Example: scrollview/scrollview.cpp.
void QScrollView::setDragAutoScroll ( bool b ) [virtual]
Sets whether autoscrolling in drag move events is enabled to b. The "dragAutoScroll" property has the full details π
void QScrollView::setHBarGeometry ( QScrollBar & hbar, int x, int y, int w, int h ) [virtual protected]
Called when the horizontal scroll bar geometry changes. It's protected on purpose so subclasses can do interesting things β like putting extra buttons in some of the space the scroll bars normally hog. π«Ά
The default implementation just gives all the space to hbar. The new geometry is given by x, y, w and h.
See also setVBarGeometry().
void QScrollView::setHScrollBarMode ( ScrollBarMode ) [virtual]
Sets the mode for the horizontal scroll bar. The "hScrollBarMode" property has the details β¨
void QScrollView::setMargins ( int left, int top, int right, int bottom ) [virtual protected]
Sets the margins around the scrolling area to left, top, right and bottom. Super useful for apps like spreadsheets with "locked" rows and columns π The marginal space is inside the frameRect() and gets left blank β so reimplement drawFrame() or drop widgets in the unused area.
By default all margins are zero.
See also frameChanged(). π
void QScrollView::setResizePolicy ( ResizePolicy ) [virtual]
Sets the resize policy. The "resizePolicy" property has all the deets π
void QScrollView::setStaticBackground ( bool y )
Sets the scrollview to have a static background if y is TRUE, or a scrolling background if y is FALSE. By default, the background is scrolling.
β οΈ Be aware that this mode is quite slow, because a full repaint of the visible area has to be triggered on every contents move. Like, every single one.
See also hasStaticBackground(). πΈ
void QScrollView::setVBarGeometry ( QScrollBar & vbar, int x, int y, int w, int h ) [virtual protected]
Called when the vertical scroll bar geometry changes. Same deal as its horizontal sibling β it's protected so subclasses can do interesting stuff like adding extra buttons where the scroll bars usually live. π
The default implementation just gives all the space to vbar. The new geometry is given by x, y, w and h.
See also setHBarGeometry().
void QScrollView::setVScrollBarMode ( ScrollBarMode ) [virtual]
Sets the mode for the vertical scroll bar. The "vScrollBarMode" property has the details π«
void QScrollView::showChild ( QWidget * child, bool y = TRUE )
π¨ This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Sets the visibility of child. Equivalent to QWidget::show() or QWidget::hide(). That's the whole thing π«Ά
int QScrollView::topMargin () const [protected]
Returns the top margin.
See also setMargins(). πΈ
void QScrollView::updateContents ( int x, int y, int w, int h )
Calls update() on a rectangle defined by x, y, w, h, translated appropriately. If the rectangle isn't visible, nothing gets repainted. π
See also repaintContents().
void QScrollView::updateContents ( const QRect & r )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Updates the contents in rectangle r
void QScrollView::updateContents () This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
okay so updateContents() with no args?? it's just the overloaded twin of the one above β same energy, fewer params. convenience behavior, we love to see it π
void QScrollView::updateScrollBars ()[slot]β refreshes the scroll bars, and bestie it considers all the possibilities. But fr fr: you should never need to call this in your own code. it's an internal-vibes-only situation, hands off πScrollBarMode QScrollView::vScrollBarMode () constβ hands you back the mode of the vertical scroll bar. for the full tea, go read the"vScrollBarMode"property, iykyk β¨QScrollBar * QScrollView::verticalScrollBar () constβ returns the component vertical scroll bar. it's exposed so you can do accelerators, autoscrolling, etc. β and that is IT. it should not be used for other purposes, periodt. also: this function never returns 0, no cap πvoid QScrollView::verticalSliderPressed ()[signal]β this signal goes off whenever the user presses the vertical slider. πvoid QScrollView::verticalSliderReleased ()[signal]β and this one fires whenever the user releases the vertical slider. the little press-and-release arc, iconic π¦QWidget * QScrollView::viewport () constβ returns the viewport widget of the scrollview. this is the widget that contains the contents widget, or which is the drawing area. πΈ
Examples:
void QScrollView::viewportPaintEvent ( QPaintEvent * pe )[virtual protected]β a low-level painting routine that draws the viewport contents. reimplement this ifdrawContents()is too high-level for your taste (like, for example, if you don't want to open aQPainteron the viewport). the paint event comes in throughpe. π₯void QScrollView::viewportResizeEvent ( QResizeEvent * )[virtual protected]β so you can do simple processing of events on the contents, this function receives all resize events sent to the viewport.
See also QWidget::resizeEvent().
Example: chart/canvasview.cpp.
QSize QScrollView::viewportSize ( int x, int y ) constβ returns the viewport size for size(x, y).
the viewport size depends on (x, y) (aka the size of the contents), the size of this widget, and the modes of the horizontal and vertical scroll bars.
this function lets widgets that trade vertical and horizontal space with each other control scroll bar appearance better. like, a word processor or web browser can control the width of the right margin accurately β whether or not there needs to be a vertical scroll bar. π
void QScrollView::viewportToContents ( int vx, int vy, int & x, int & y ) constβ translates a point(vx, vy)on theviewport()widget to a point(x, y)in the contents. πQPoint QScrollView::viewportToContents ( const QPoint & vp ) constβ overloaded member function, provided for convenience. it behaves essentially like the above function.
returns the point on the viewport vp translated to a point in the contents. π«Ά
int QScrollView::visibleHeight () constβ returns the vertical amount of the content that is visible. see the"visibleHeight"property for details. πint QScrollView::visibleWidth () constβ returns the horizontal amount of the content that is visible. see the"visibleWidth"property for details. π
π Property Documentation π
int contentsHeight
this property holds the height of the contents area.
get this property's value with contentsHeight(). β¨
int contentsWidth
this property holds the width of the contents area.
get this property's value with contentsWidth(). β¨
int contentsX
this property holds the X coordinate of the contents that are at the left edge of the viewport.
get this property's value with contentsX(). πΈ
int contentsY
this property holds the Y coordinate of the contents that are at the top edge of the viewport.
get this property's value with contentsY(). πΈ
bool dragAutoScroll
this property holds whether autoscrolling in drag move events is enabled.
if this property is set to TRUE (which is the default, bestie), the QScrollView automatically scrolls the contents in drag move events when the user moves the cursor close to a border of the view. obviously this only works if the viewport accepts drops. specifying FALSE disables this autoscroll feature entirely. π
β οΈ Warning: enabling this property might not be enough to effectively turn on autoscrolling. if you put a custom widget in the QScrollView, you might need to callQDragEvent::ignore()on the event in thedragEnterEvent()anddragMoveEvent()reimplementations. don't skip this step, it's giving "I set the flag and nothing happened" π
set this property's value with setDragAutoScroll() and get this property's value with dragAutoScroll(). π₯
ScrollBarMode hScrollBarMode
this property holds the mode for the horizontal scroll bar.
the default mode is QScrollView::Auto. π¦
See also vScrollBarMode.
set this property's value with setHScrollBarMode() and get this property's value with hScrollBarMode(). β¨
ResizePolicy resizePolicy
this property holds the resize policy.
the default is Default. π
See also ResizePolicy.
set this property's value with setResizePolicy() and get this property's value with resizePolicy(). β¨
ScrollBarMode vScrollBarMode
this property holds the mode for the vertical scroll bar.
the default mode is QScrollView::Auto. π¦
See also hScrollBarMode.
set this property's value with setVScrollBarMode() and get this property's value with vScrollBarMode(). β¨
int visibleHeight
this property holds the vertical amount of the content that is visible.
get this property's value with visibleHeight(). π
int visibleWidth
this property holds the horizontal amount of the content that is visible.
get this property's value with visibleWidth(). π
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. (yes, the whole statement lives in that file, go read it bestie π)
βοΈ AUTHOR βοΈ
Generated automatically from the source code. (no human author to stan, just the machine doing its thing π€)
π BUGS π
if you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. good bug reports help us to help you. thank you!! π«Ά (this is real, thorough bug reports are the love language of maintainers)
the definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. this man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. so like, it's a vibe, not the canon π
if you find errors in this manual page, please report them to qt-bugs@trolltech.com. please include the name of the manual page (qscrollview.3qt) and the Qt version (3.3.8). include both, don't make them guess, that's the group-chat-etiquette of bug reporting β¨
okay and that's a wrap on the whole thing, bestie π this page came from Trolltech AS, dated 2 February 2007, and it's the man page for QScrollView(3qt) β version 3.3.8 energy, and you ate every last section. go build something iconic with it. πβ¨π¦
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms