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

📄 qscrollview.3qt

📁 Trolltech公司发布的基于C++图形开发环境
💻 3QT
📖 第 1 页 / 共 3 页
字号:
.br    QVBox* big_box = new QVBox(sv->viewport());.br    sv->addChild(big_box);.fi.PPYou may 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    ....fi.PPHere, the QScrollView has 4 children - the viewport(), the verticalScrollBar(), the horizontalScrollBar(), and a small cornerWidget(). The viewport() has 1 child, the big QVBox. The QVBox has the three labels as child widgets. When the view is scrolled, the QVBox is moved, and its children move with it as child widgets normally do..IP "\fBVery Big View, some Widgets\fR" 1c.PP.ce 1.B "[Image Omitted]".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);.fi.PPHere, the QScrollView has the same 4 children - the viewport(), the verticalScrollBar(), the horizontalScrollBar(), and a small cornerWidget(). The viewport() has the three labels as child widgets. When the view is scrolled, the scrollview moves the child widgets individually..IP "\fBVery Big View, many Widgets\fR" 1c.PP.ce 1.B "[Image Omitted]".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);.fi.PPHere, the QScrollView has 4 children - the clipper() (\fInot\fR the viewport() this time), the verticalScrollBar(), the horizontalScrollBar(), and a small cornerWidget(). The clipper() has 1 child - the viewport(). The viewport() has the three labels as child widgets. When the view is scrolled, the viewport() is moved, and its children move with it as child widgets normally do..PPNormally 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 (since drag-and-drop events propagate to the parent), but to work out what 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 overriding mousePressEvent(), reimplement viewportMousePressEvent() instead (if you reimplement mousePressEvent() you'll only get called 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 being covered up by the viewport, clipper, or scrollbars..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 \fCWResizeNoErase, WNorthWestGravity, WRepaintNoErase\fR and \fCWPaintClever.\fR See Qt::WidgetFlags for documentation about these flags. Here are some examples: .TPAn image manipulation widget would use \fCWResizeNoErase|WNorthWestGravity,\fR because the widget draws all pixels itself and when the size increases, it only needs a paint event for the new part, since the old part remains unchanged..TPA word processing widget might use \fCWResizeNoErase\fR and repaint itself line by line to get a less flickery resizing. If the widget is in a mode where no text justification can take place, it might use \fCWNorthWestGravity\fR too, so that it would only get a repaint for the newly visible parts..TPA scrolling game widget where the background scrolls as the characters move might use \fCWRepaintNoErase\fR (in addition to \fCWNorthWestGravity\fR and \fCWResizeNoErase)\fR so that the window system background does not flash in and out during scrolling..PP\fBWarning:\fR WResizeNoErase is currently set by default, i.e. you always have to 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]".PPExamples:.(lscrollview/scrollview.cpp.)l.SS "Member Type Documentation".SH "QScrollView::ResizePolicy"This enum type is used to control QScrollView's reaction to resize events. There are four possible settings:.TP\fCDefault\fR - QScrollView selects one of the other settings automatically when it has to. In this version of Qt, QScrollView changes to \fCManual\fR if you resize the contents with resizeContents(), and to \fCAutoOne\fR if a child is added..TP\fCManual\fR - the view stays the size set by resizeContents()..TP\fCAutoOne\fR - if there is only child widget, the view stays the size of that widget. Otherwise, the behaviour is undefined..TP\fCAutoOneFit\fR - if there is only one child widget the view stays the size of that widget's sizeHint(). If the scrollview is resized bigger than the child's sizeHint(), the child will be resized to fit. If there is more than one child, the behaviour is undefined..IP.SH "QScrollView::ScrollBarMode"This enum type describes the various modes of QScrollView's scroll bars. The defined modes are: .TP\fCAuto\fR - QScrollView shows a scrollbar when the content is too tall to fit and not else. This is the default..TP\fCAlwaysOff\fR - QScrollView never shows a scrollbar..TP\fCAlwaysOn\fR - QScrollView always shows a scrollbar..IP.PP(The modes for the horizontal and vertical scroll bars are independent.)..PPExamples:.(lscrollview/scrollview.cpp.)l.SH MEMBER FUNCTION DOCUMENTATION.SH "QScrollView::QScrollView ( QWidget * parent=0, const char * name=0, WFlags f=0 )"Constructs a QScrollView with a \fIparent,\fR a \fIname\fR and widget flags \fIf.\fR.PPThe widget flags \fCWNorthWestGravity, WRepaintNoErase\fR and \fCWPaintClever\fR are propagated to the viewport() widget. The other widget flags are propagated to the parent constructor as usual..SH "QScrollView::~QScrollView ()"Destructs the QScrollView. Any children added with addChild() will be destructed..SH "void QScrollView::addChild ( QWidget * child, int x=0, int y=0 ) \fC[virtual]\fR"Inserts \fIchild\fR into the scrolled area positioned at (\fIx, y).\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..PPExamples:.(lscrollview/scrollview.cpp.)l.SH "int QScrollView::bottomMargin () const \fC[protected]\fR"Returns the current bottom margin..PPSee also setMargins()..SH "void QScrollView::center ( int x, int y ) \fC[slot]\fR"Scrolls the content so that the point (x,y) is in the center of visible area..SH "void QScrollView::center ( int x, int y, float xmargin, float ymargin ) \fC[slot]\fR"Scrolls the content so that the point (x,y) is visible, with the given margins (as fractions of visible area)..PPeg..TPMargin 0.0 allows (x,y) to be on edge of visible area..TPMargin 0.5 ensures (x,y) is in middle 50% of visible area..TPMargin 1.0 ensures (x,y) is in the center of the visible area..SH "bool QScrollView::childIsVisible ( QWidget * child )"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. 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 child 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 child 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 is ultimately clipped to be inside the clipper widget..PPYou should not need to access this..PPSee also visibleWidth() and visibleHeight()..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..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..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..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..SH "int QScrollView::contentsHeight () const"Returns the height of the contents area..SH "void QScrollView::contentsMouseDoubleClickEvent ( QMouseEvent * ) \fC[virtual protected]\fR"This event handler is called whenever the QScrollView receives a mouseDoubleClickEvent() - the click position is translated to be a point on the contents..PPReimplemented in QListView and QTable..SH "void QScrollView::contentsMouseMoveEvent ( QMouseEvent * ) \fC[virtual protected]\fR"This event handler is called whenever the QScrollView receives a mouseMoveEvent() - the mouse position is translated to be a point on the contents..PPReimplemented in QListView and QTable..SH "void QScrollView::contentsMousePressEvent ( QMouseEvent * ) \fC[virtual protected]\fR"This event handler is called whenever the QScrollView receives a mousePressEvent() - the press position is translated to be a point on the contents..PPReimplemented in QTable and QListView..SH "void QScrollView::contentsMouseReleaseEvent ( QMouseEvent * ) \fC[virtual protected]\fR"This event handler is called whenever the QScrollView receives a mouseReleaseEvent() - the release position is translated to be a point on the contents..PPReimplemented in QListView and QTable..SH "void QScrollView::contentsMoving ( int x, int y ) \fC[signal]\fR"This signal is emitted just before the contents is moved to the given position..PPSee also contentsX() and contentsY()..SH "QPoint QScrollView::contentsToViewport ( const QPoint & p )"Returns the point \fIp\fR translated to a point on the viewport() widget..SH "void QScrollView::contentsToViewport ( int x, int y, int & vx, int & vy )"Translates a point (\fIx, y)\fR in the contents to a point (\fIvx, vy)\fR 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() - the mouse position is translated to be a point on the contents..SH "int QScrollView::contentsWidth () const"Returns the width of the contents area..SH "int QScrollView::contentsX () const"Returns the X coordinate of the contents which is at the left edge of the viewport..SH "int QScrollView::contentsY () const"Returns the Y coordinate of the contents which is at the top edge of the viewport..SH "QWidget* QScrollView::cornerWidget () const"Returns the widget in the corner between the two scrollbars..PPBy default, no corner widget is present..PPExamples:.(lscrollview/scrollview.cpp.)l.SH "bool QScrollView::dragAutoScroll () const"Returns TRUE if autoscrolling in drag move events is enabled, else FALSE..PPSee also setDragAutoScroll()..SH "void QScrollView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ) \fC[virtual protected]\fR"Reimplement this method if you are viewing a drawing area rather than a widget..PPThe function should draw the rectangle (\fIclipx, clipy, clipw, cliph\fR ) of the contents, using painter \fIp.\fR The clip rectangle is in the scroll views'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;.br.br    // Clip the coordinates so X/Windows will not have problems....br    if (x1 < clipx) x1=clipx;.br    if (y1 < clipy) y1=clipy;.br    if (x2 > clipx+clipw-1) x2=clipx+clipw-1;.br    if (y2 > clipy+cliph-1) y2=clipy+cliph-1;.br.br    // Paint using the small coordinates....br    if ( x2 >= x1 && y2 >= y1 ).br        p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red);.br  }.fi.PPThe clip rectangle and translation of the painter \fIp\fR is already set appropriately..PPReimplemented in QTable and QCanvasView..SH "void QScrollView::drawContentsOffset ( QPainter * p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph ) \fC[virtual protected]\fR"For backward compatibility only. It is easier to use drawContents(QPainter*,int,int,int,int)..PPThe default implementation translates the painter appropriately and calls drawContents(QPainter*,int,int,int,int)..PPReimplemented in QTextView and QListView..SH "void QScrollView::enableClipper ( bool y )"When large numbers of child widgets are in a scrollview, especially if they are close together, the scrolling performance can suffer greatly. If you call enableClipper(TRUE), the scrollview will use an extra widget to group child widgets..PPNote that you may only call enableClipper() prior to adding widgets..PPFor a full discussion, see the overview documentation of this class..PPExamples:.(lscrollview/scrollview.cpp.)l.SH "void QScrollView::ensureVisible ( int x, int y ) \fC[slot]\fR"Scrolls the content so that the point (x, y) is visible with at least 50-pixel margins (if possible, otherwise centered)..SH "void QScrollView::ensureVisible ( int x, int y, int xmargin, int ymargin ) \fC[slot]\fR"Scrolls the content so that the point (x, y) is visible with at least the given pixel margins (if possible, otherwise centered)..SH "bool QScrollView::eventFilter ( QObject * obj, QEvent * e ) \fC[virtual protected]\fR"This event filter ensures the scrollbars are updated when a single contents widget is resized, shown, hidden, or destroyed, and passes mouse events to the QScrollView..PPReimplemented from QObject..SH "bool QScrollView::focusNextPrevChild ( bool next ) \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QWidget..SH "void QScrollView::frameChanged () \fC[virtual protected]\fR"Reimplemented for internal reasons; the API is not affected..PPReimplemented from QFrame..SH "QScrollView::ScrollBarMode QScrollView::hScrollBarMode() const"Returns the currently set mode for the horizontal scrollbar..PPSee also setHScrollBarMode()..PPExamples:

⌨️ 快捷键说明

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