|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QAbstractSlider
com.trolltech.qt.gui.QScrollBar
public class QScrollBar
The QScrollBar widget provides a vertical or horizontal scroll bar.
A scroll bar is a control that enables the user to access parts of a document that is larger than the widget used to display it. It provides a visual indication of the user's current position within the document and the amount of the document that is visible. Scroll bars are usually equipped with other controls that enable more accurate navigation. Qt displays scroll bars in a way that is appropriate for each platform.
If you need to provide a scrolling view onto another widget, it may be more convenient to use the QScrollArea class because this provides a viewport widget and scroll bars. QScrollBar is useful if you need to implement similar functionality for specialized widgets using QAbstractScrollArea; for example, if you decide to subclass QAbstractItemView. For most other situations where a slider control is used to obtain a value within a given range, the QSlider class may be more appropriate for your needs.
Scroll bars typically include four separate controls: a slider, scroll arrows, and a page control.
|
Each scroll bar has a value that indicates how far the slider is from the start of the scroll bar; this is obtained with value and set with setValue. This value always lies within the range of values defined for the scroll bar, from minimum() to maximum() inclusive. The range of acceptable values can be set with setMinimum and setMaximum. At the minimum value, the top edge of the slider (for a vertical scroll bar) or left edge (for a horizontal scroll bar) will be at the top (or left) end of the scroll bar. At the maximum value, the bottom (or right) edge of the slider will be at the bottom (or right) end of the scroll bar.
The length of the slider is usually related to the value of the page step, and typically represents the proportion of the document area shown in a scrolling view. The page step is the amount that the value changes by when the user presses the Page Up and Page Down keys, and is set with setPageStep. Smaller changes to the value defined by the line step are made using the cursor keys, and this quantity is set with setLineStep().
Note that the range of values used is independent of the actual size of the scroll bar widget. You do not need to take this into account when you choose values for the range and the page step.
The range of values specified for the scroll bar are often determined differently to those for a QSlider because the length of the slider needs to be taken into account. If we have a document with 100 lines, and we can only show 20 lines in a widget, we may wish to construct a scroll bar with a page step of 20, a minimum value of 0, and a maximum value of 80. This would give us a scroll bar with five "pages".
![]() | The relationship between a document length, the range of values used in a scroll bar, and the page step is simple in many common situations. The scroll bar's range of values is determined by subtracting a chosen page step from some value representing the length of the document. In such cases, the following equation is useful: |
QScrollBar only provides integer ranges. Note that although QScrollBar handles very large numbers, scroll bars on current screens cannot usefully represent ranges above about 100,000 pixels. Beyond that, it becomes difficult for the user to control the slider using either the keyboard or the mouse, and the scroll arrows will have limited use.
ScrollBar inherits a comprehensive set of signals from QAbstractSlider:
A scroll bar can be controlled by the keyboard, but it has a default focusPolicy of Qt::NoFocus. Use setFocusPolicy to enable keyboard interaction with the scroll bar:
The slider itself can be controlled by using the triggerAction() function to simulate user interaction with the scroll bar controls. This is useful if you have many different widgets that use a common range of values.
Most GUI styles use the pageStep value to calculate the size of the slider.
![]() | A scroll bar shown in the Macintosh widget style. |
![]() | A scroll bar shown in the Windows XP widget style. |
![]() | A scroll bar shown in the Plastique widget style. |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QAbstractSlider |
---|
QAbstractSlider.SliderAction, QAbstractSlider.SliderChange |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.gui.QAbstractSlider |
---|
actionTriggered, rangeChanged, sliderMoved, sliderPressed, sliderReleased, valueChanged |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QScrollBar()
Equivalent to QScrollBar(0). |
|
QScrollBar(Qt.Orientation arg__1)
Equivalent to QScrollBar(arg__1, 0). |
|
QScrollBar(Qt.Orientation arg__1,
QWidget parent)
Constructs a scroll bar with the given arg__1. |
|
QScrollBar(QWidget parent)
Constructs a vertical scroll bar. |
Method Summary | |
---|---|
protected void |
contextMenuEvent(QContextMenuEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive widget context menu events. |
boolean |
event(QEvent event)
This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead. Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent. Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event. This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops. |
static QScrollBar |
fromNativePointer(QNativePointer nativePointer)
This function returns the QScrollBar instance pointed to by nativePointer |
protected void |
hideEvent(QHideEvent arg__1)
This event handler can be reimplemented in a subclass to receive widget hide events. |
protected void |
initStyleOption(QStyleOptionSlider option)
Initialize option with the values from this QScrollBar. |
protected void |
mouseMoveEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget. |
protected void |
mousePressEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse press events for the widget. |
protected void |
mouseReleaseEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse release events for the widget. |
protected void |
paintEvent(QPaintEvent arg__1)
This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter. |
QSize |
sizeHint()
Returns the recommended size for the widget. |
protected void |
sliderChange(QAbstractSlider.SliderChange change)
Reimplement this virtual function to track slider changes such as SliderRangeChange, SliderOrientationChange, SliderStepsChange, or SliderValueChange. |
Methods inherited from class com.trolltech.qt.gui.QAbstractSlider |
---|
changeEvent, hasTracking, invertedAppearance, invertedControls, isSliderDown, keyPressEvent, maximum, minimum, orientation, pageStep, repeatAction, setInvertedAppearance, setInvertedControls, setMaximum, setMinimum, setOrientation, setPageStep, setRange, setRepeatAction, setRepeatAction, setRepeatAction, setSingleStep, setSliderDown, setSliderPosition, setTracking, setValue, singleStep, sliderPosition, timerEvent, triggerAction, value, wheelEvent |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QScrollBar()
Equivalent to QScrollBar(0).
public QScrollBar(QWidget parent)
Constructs a vertical scroll bar.
The parent arguments is sent to the QWidget constructor.
The minimum defaults to 0, the maximum to 99, with a singleStep size of 1 and a pageStep size of 10, and an initial value of 0.
public QScrollBar(Qt.Orientation arg__1)
Equivalent to QScrollBar(arg__1, 0).
public QScrollBar(Qt.Orientation arg__1, QWidget parent)
Constructs a scroll bar with the given arg__1.
The parent argument is passed to the QWidget constructor.
The minimum defaults to 0, the maximum to 99, with a singleStep size of 1 and a pageStep size of 10, and an initial value of 0.
Method Detail |
---|
protected void contextMenuEvent(QContextMenuEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive widget context menu events.
The handler is called when the widget's contextMenuPolicy is Qt::DefaultContextMenu.
The default implementation ignores the context event. See the QContextMenuEvent documentation for more details.
contextMenuEvent
in class QWidget
public boolean event(QEvent event)
This is the main event handler; it handles event arg__1. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.
Key press and release events are treated differently from other events. event checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event calls keyPressEvent.
Mouse and tablet event handling is also slightly special: only when the widget is enabled, event will call the specialized handlers such as mousePressEvent; otherwise it will discard the event.
This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.
event
in class QAbstractSlider
protected void hideEvent(QHideEvent arg__1)
This event handler can be reimplemented in a subclass to receive widget hide events. The event is passed in the arg__1 parameter.
Hide events are sent to widgets immediately after they have been hidden.
Note: A widget receives spontaneous show and hide events when its mapping status is changed by the window system, e.g. a spontaneous hide event when the user minimizes the window, and a spontaneous show event when the window is restored again. After receiving a spontaneous hide event, a widget is still considered visible in the sense of isVisible.
hideEvent
in class QWidget
visible
,
event,
QHideEventprotected void mouseMoveEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
mouseMoveEvent
in class QWidget
Example
protected void mousePressEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent the mouseReleaseEvent may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
mousePressEvent
in class QWidget
Example
protected void mouseReleaseEvent(QMouseEvent arg__1)
This event handler, for event arg__1, can be reimplemented in a subclass to receive mouse release events for the widget.
mouseReleaseEvent
in class QWidget
Example
protected void paintEvent(QPaintEvent arg__1)
This event handler can be reimplemented in a subclass to receive paint events which are passed in the arg__1 parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint or update, or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint does not permit this optimization, so we suggest using update whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole and setPalette.
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
... extern void qt_x11_set_global_double_buffer(bool); qt_x11_set_global_double_buffer(false); ...
Note: In general, one should refrain from calling update or repaint inside of paintEvent. For example, calling update or repaint on children inside a paintEvent results in undefined behavior; the child may or may not get a paint event.
paintEvent
in class QWidget
public QSize sizeHint()
Returns the recommended size for the widget.
If the value of this property is an invalid size, no size is recommended.
The default implementation of sizeHint returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise.
sizeHint
in class QWidget
protected void sliderChange(QAbstractSlider.SliderChange change)
Reimplement this virtual function to track slider changes such as SliderRangeChange, SliderOrientationChange, SliderStepsChange, or SliderValueChange. The default implementation only updates the display and ignores the change parameter.
sliderChange
in class QAbstractSlider
public static QScrollBar fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.protected final void initStyleOption(QStyleOptionSlider option)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |