⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qscrollview.3qt

📁 Linux下的基于X11的图形开发环境。
💻 3QT
📖 第 1 页 / 共 3 页
字号:
.BI "virtual void \fBsetVBarGeometry\fR ( QScrollBar & vbar, int x, int y, int w, int h )".br.ti -1c.BI "virtual bool \fBeventFilter\fR ( QObject * obj, QEvent * e )".br.in -1c.SH DESCRIPTIONThe QScrollView widget provides a scrolling area with on-demand scroll bars..PPThe QScrollView is a large canvas - potentially larger than the coordinate system normally supported by the underlying window system. This is important because it is quite easy to go beyond these limitations (e.g. many web pages are more than 32000 pixels high). Additionally, the QScrollView can have QWidgets positioned on it that scroll around with the drawn content. These sub-widgets can also have positions outside the normal coordinate range (but they are still limited in size)..PPTo provide content for the widget, 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..PPTo use QScrollView effectively it is important to understand its widget structure in the three styles of use: a single large child widget, a large panning area with some widgets and a large panning area with many widgets..SH "Using One Big Widget"<center>.ce 1.B "[Image Omitted]".PP</center>.PPThe 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). 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():.PP.nf.br        QScrollView* sv = new QScrollView(...);.br        QVBox* big_box = new QVBox(sv->viewport());.br        sv->addChild(big_box);.br.fiYou can go on to add arbitrary child widgets to the single child in the scrollview as you would with any widget:.PP.nf.br        QLabel* child1 = new QLabel("CHILD", big_box);.br        QLabel* child2 = new QLabel("CHILD", big_box);.br        QLabel* child3 = new QLabel("CHILD", big_box);.br        ....br.fi.PPHere 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..SH "Using a Very Big View with Some Widgets"<center>.ce 1.B "[Image Omitted]".PP</center>.PPThe 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):.PP.nf.br        QScrollView* sv = new QScrollView(...);.br        QLabel* child1 = new QLabel("CHILD", sv->viewport());.br        sv->addChild(child1);.br        QLabel* child2 = new QLabel("CHILD", sv->viewport());.br        sv->addChild(child2);.br        QLabel* child3 = new QLabel("CHILD", sv->viewport());.br        sv->addChild(child3);.br.fiHere, 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..SH "Using a Very Big View with Many Widgets"<center>.ce 1.B "[Image Omitted]".PP</center>.PPThe 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():.PP.nf.br        QScrollView* sv = new QScrollView(...);.br        sv->enableClipper(TRUE);.br        QLabel* child1 = new QLabel("CHILD", sv->viewport());.br        sv->addChild(child1);.br        QLabel* child2 = new QLabel("CHILD", sv->viewport());.br        sv->addChild(child2);.br        QLabel* child3 = new QLabel("CHILD", sv->viewport());.br        sv->addChild(child3);.br.fi.PPHere, the QScrollView has four children: the clipper() (not the viewport() this time), 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..SH "Details Relevant for All Views"Normally you will use the first or third method if you want any child widgets in the view..PPNote that the widget you see in the scrolled area is the viewport() widget, not the QScrollView itself. So to turn mouse tracking on, for example, use viewport()->setMouseTracking(TRUE)..PPTo enable drag-and-drop, you would setAcceptDrops(TRUE) on the QScrollView (because drag-and-drop events propagate to the parent). But to work out the logical position in the view, you would need to map the drop co-ordinate from being relative to the QScrollView to being relative to the contents; use the function viewportToContents() for this..PPTo 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 handers 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..PPWhen 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 WResizeNoErase, WStaticContents, WRepaintNoErase and WPaintClever. See Qt::WidgetFlags for documentation about these flags. Here are some examples:.IP.TPAn image-manipulation widget would use \fCWResizeNoErase|WStaticContents\fR because 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..IP.TPA word processing widget might use WResizeNoErase and 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 use WStaticContents too, so that it would only get a repaint for the newly visible parts..IP.TPA scrolling game widget in which the background scrolls as the characters move might use WRepaintNoErase (in addition to WStaticContents and WResizeNoErase) so that the window system background does not flash in and out during scrolling..IP.PPChild widgets may be moved using addChild() or moveChild(). Use childX() and childY() to get the position of a child widget..PPA 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()..PPThe 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..PPCoordinate conversion is provided by contentsToViewport() and viewportToContents()..PPThe contentsMoving() signal is emitted just before the contents are moved to a new position..PP\fBWarning:\fR WResizeNoErase is currently set by default, 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 the flag explicitly..PP.ce 1.B "[Image Omitted]".PP.ce 1.B "[Image Omitted]".PPSee also Abstract Widget Classes..SS "Member Type Documentation".SH "QScrollView::ResizePolicy"This enum type is used to control a QScrollView's reaction to resize events..TP\fCQScrollView::Default\fR - the QScrollView selects one of the other settings automatically when it has to. In this version of Qt, QScrollView changes to Manual if you resize the contents with resizeContents() and to AutoOne if a child is added..TP\fCQScrollView::Manual\fR - the view stays the size set by resizeContents()..TP\fCQScrollView::AutoOne\fR - if there is only one child widget the view stays the size of that widget. Otherwise the behaviour is undefined..TP\fCQScrollView::AutoOneFit\fR - if there is only one child widget the view stays the size of that widget's sizeHint(). If the scrollview is resized larger than the child's sizeHint(), the child will be resized to fit. If there is more than one child, the behaviour is undefined..SH "QScrollView::ScrollBarMode"This enum type describes the various modes of QScrollView's scroll bars..TP\fCQScrollView::Auto\fR - QScrollView shows a scroll bar when the content is too large to fit and not otherwise. This is the default..TP\fCQScrollView::AlwaysOff\fR - QScrollView never shows a scroll bar..TP\fCQScrollView::AlwaysOn\fR - QScrollView always shows a scroll bar..PP(The modes for the horizontal and vertical scroll bars are independent.).SH MEMBER FUNCTION DOCUMENTATION.SH "QScrollView::QScrollView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )"Constructs a QScrollView called \fIname\fR with parent \fIparent\fR and widget flags \fIf\fR..PPThe widget flags WStaticContents, WRepaintNoErase and WPaintClever are propagated to the viewport() widget. The other widget flags are propagated to the parent constructor as usual..SH "QScrollView::~QScrollView ()"Destroys the QScrollView. Any children added with addChild() will be deleted..SH "void QScrollView::addChild ( QWidget * child, int x = 0, int y = 0 )\fC [virtual]\fR"Inserts the widget, \fIchild\fR, into the scrolled area positioned at (\fIx\fR, \fIy\fR). The position defaults to (0, 0). If the child is already in the view, it is just moved..PPYou may want to call enableClipper(TRUE) if you add a large number of widgets..PPExample: scrollview/scrollview.cpp..SH "int QScrollView::bottomMargin () const\fC [protected]\fR"Returns the bottom margin..PPSee also setMargins()..SH "void QScrollView::center ( int x, int y )\fC [slot]\fR"Scrolls the content so that the point \fI(x, y)\fR is in the center of visible area..PPExample: scrollview/scrollview.cpp..SH "void QScrollView::center ( int x, int y, float xmargin, float ymargin )\fC [slot]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPScrolls the content so that the point \fI(x, y)\fR is visible with the \fIxmargin\fR and \fIymargin\fR margins (as fractions of visible the area)..PPFor example:.TPMargin 0.0 allows (x, y) to be on the edge of the visible area..TPMargin 0.5 ensures that (x, y) is in middle 50% of the visible area..TPMargin 1.0 ensures that (x, y) is in the center of the the visible area..SH "bool QScrollView::childIsVisible ( QWidget * child )"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPReturns TRUE if \fIchild\fR is visible. This is equivalent to child->isVisible()..SH "int QScrollView::childX ( QWidget * child )"Returns the X position of the given \fIchild\fR widget. Use this rather than QWidget::x() for widgets added to the view..SH "int QScrollView::childY ( QWidget * child )"Returns the Y position of the given \fIchild\fR widget. Use this rather than QWidget::y() for widgets added to the view..SH "QWidget * QScrollView::clipper () const"Returns the clipper widget. Contents in the scrollview are ultimately clipped to be inside the clipper widget..PPYou should not need to use this function..PPSee also visibleWidth and visibleHeight..SH "void QScrollView::contentsContextMenuEvent ( QContextMenuEvent * e )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a contextMenuEvent() in \fIe\fR: the mouse position is translated to be a point on the contents..PPExample: chart/canvasview.cpp..SH "void QScrollView::contentsDragEnterEvent ( QDragEnterEvent * )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a dragEnterEvent(): the drag position is translated to be a point on the contents..PPReimplemented in QTable..SH "void QScrollView::contentsDragLeaveEvent ( QDragLeaveEvent * )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a dragLeaveEvent(): the drag position is translated to be a point on the contents..PPReimplemented in QTable..SH "void QScrollView::contentsDragMoveEvent ( QDragMoveEvent * )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a dragMoveEvent(): the drag position is translated to be a point on the contents..PPReimplemented in QTable..SH "void QScrollView::contentsDropEvent ( QDropEvent * )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a dropEvent(): the drop position is translated to be a point on the contents..PPReimplemented in QTable..SH "int QScrollView::contentsHeight () const"Returns the height of the contents area. See the "contentsHeight" property for details..SH "void QScrollView::contentsMouseDoubleClickEvent ( QMouseEvent * e )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a mouseDoubleClickEvent(): the click position in \fIe\fR is translated to be a point on the contents..PPReimplemented in QListView..SH "void QScrollView::contentsMouseMoveEvent ( QMouseEvent * e )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a mouseMoveEvent(): the mouse position in \fIe\fR is translated to be a point on the contents..PPExamples:.)l canvas/canvas.cpp and chart/canvasview.cpp..PPReimplemented in QListView..SH "void QScrollView::contentsMousePressEvent ( QMouseEvent * e )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a mousePressEvent(): the press position in \fIe\fR is translated to be a point on the contents..PPExamples:.)l canvas/canvas.cpp and chart/canvasview.cpp..PPReimplemented in QListView..SH "void QScrollView::contentsMouseReleaseEvent ( QMouseEvent * e )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a mouseReleaseEvent(): the release position in \fIe\fR is translated to be a point on the contents..PPReimplemented in QListView..SH "void QScrollView::contentsMoving ( int x, int y )\fC [signal]\fR"This signal is emitted just before the contents are moved to position \fI(x, y)\fR..PPSee also contentsX and contentsY..SH "void QScrollView::contentsToViewport ( int x, int y, int & vx, int & vy ) const"Translates a point (\fIx\fR, \fIy\fR) in the contents to a point (\fIvx\fR, \fIvy\fR) on the viewport() widget..SH "QPoint QScrollView::contentsToViewport ( const QPoint & p ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the point \fIp\fR translated to a point on the viewport() widget..SH "void QScrollView::contentsWheelEvent ( QWheelEvent * e )\fC [virtual protected]\fR"This event handler is called whenever the QScrollView receives a wheelEvent() in \fIe\fR: the mouse position is translated to be a point on the contents..SH "int QScrollView::contentsWidth () const"Returns the width of the contents area. See the "contentsWidth" property for details..SH "int QScrollView::contentsX () const"Returns the X coordinate of the contents that are at the left edge of the viewport. See the "contentsX" property for details..SH "int QScrollView::contentsY () const"Returns the Y coordinate of the contents that are at the top edge of the viewport. See the "contentsY" property for details..SH "QWidget * QScrollView::cornerWidget () const"Returns the widget in the corner between the two scroll bars..PPBy default, no corner widget is present..PPExample: scrollview/scrollview.cpp..SH "bool QScrollView::dragAutoScroll () const"Returns TRUE if autoscrolling in drag move events is enabled; otherwise returns FALSE. See the "dragAutoScroll" property for details..SH "void QScrollView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph )\fC [virtual protected]\fR"Reimplement this function if you are viewing a drawing area rather than a widget..PPThe function should draw the rectangle (\fIclipx\fR, \fIclipy\fR, \fIclipw\fR, \fIcliph\fR) of the contents using painter \fIp\fR. The clip rectangle is in the scrollview's coordinates..PPFor example:.PP.nf.br    {.br        // Fill a 40000 by 50000 rectangle at (100000,150000).br.br        // Calculate the coordinates....br        int x1 = 100000, y1 = 150000;.br        int x2 = x1+40000-1, y2 = y1+50000-1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -