Q3RangeControl Class

The Q3RangeControl 类提供在范围内的整数值。 更多...

头: #include <Q3RangeControl>

公共函数

Q3RangeControl ()
Q3RangeControl (int minValue , int maxValue , int lineStep , int pageStep , int value )
virtual ~Q3RangeControl ()
void addLine ()
void addPage ()
int bound (int v ) const
int lineStep () const
int maxValue () const
int minValue () const
int pageStep () const
void setMaxValue (int maxVal )
void setMinValue (int minVal )
void setRange (int minValue , int maxValue )
void setSteps (int lineStep , int pageStep )
void setValue (int value )
void subtractLine ()
void subtractPage ()
int value () const

保护函数

void directSetValue (int value )
int positionFromValue (int logical_val , int span ) const
int prevValue () const
virtual void rangeChange ()
virtual void stepChange ()
virtual void valueChange ()
int valueFromPosition (int pos , int span ) const

详细描述

The Q3RangeControl 类提供在范围内的整数值。

Although originally designed for the QScrollBar widget, the Q3RangeControl can also be used in conjunction with other widgets such as QSlider and QSpinBox . Here are the five main concepts in the class:

  1. Current value The bounded integer that Q3RangeControl 维护。 value () returns it, and several functions, including setValue (), set it.
  2. Minimum The lowest value that value () can ever return. Returned by minValue () and set by setRange () or one of the constructors.
  3. Maximum The highest value that value () can ever return. Returned by maxValue () and set by setRange () or one of the constructors.
  4. Line step The smaller of two natural steps that Q3RangeControl provides and typically corresponds to the user pressing an arrow key. The line step is returned by lineStep () and set using setSteps ()。函数 addLine () 和 subtractLine () respectively increment and decrement the current value by lineStep ().
  5. Page step The larger of two natural steps that Q3RangeControl provides and typically corresponds to the user pressing PageUp or PageDown. The page step is returned by pageStep () and set using setSteps ()。函数 addPage () and substractPage() respectively increment and decrement the current value by pageStep ().

可以将整体 1 视为第 3 步幅大小。 setValue () 允许将当前值设为在允许范围内的任何整数,不仅仅是 minValue () + n * lineStep () 对于整数值 n 。某些 Widget 可能允许用户设置任何根本值;其它 Widget 可能仅仅提供倍增 lineStep () 或 pageStep ().

Q3RangeControl provides three virtual functions that are well suited for updating the on-screen representation of range controls and emitting signals: valueChange (), rangeChange () 和 stepChange ().

Q3RangeControl also provides a function called bound () which lets you force arbitrary integers to be within the allowed range of the range control.

We recommend that all widgets that inherit Q3RangeControl provide at least a signal called valueChanged(); many widgets will want to provide addStep(), addPage (), substractStep() and substractPage() as slots.

Note that you must use multiple inheritance if you plan to implement a widget using Q3RangeControl 因为 Q3RangeControl is not derived from QWidget .

成员函数文档编制

Q3RangeControl:: Q3RangeControl ()

Constructs a range control with a minimum value of 0, maximum value of 99, line step of 1, page step of 10 and initial value 0.

Q3RangeControl:: Q3RangeControl ( int minValue , int maxValue , int lineStep , int pageStep , int value )

Constructs a range control whose value can never be smaller than minValue or greater than maxValue , whose line step size is lineStep and page step size is pageStep and whose value is initially value (which is guaranteed to be in range using bound ()).

[虚拟] Q3RangeControl:: ~Q3RangeControl ()

Destroys the range control

void Q3RangeControl:: addLine ()

相当于 setValue(value() + lineStep()) .

If the value is changed, then valueChange () 被调用。

另请参阅 subtractLine (), addPage (),和 setValue ().

void Q3RangeControl:: addPage ()

相当于 setValue(value() + pageStep()) .

If the value is changed, then valueChange () 被调用。

另请参阅 subtractPage (), addLine (),和 setValue ().

int Q3RangeControl:: bound ( int v ) const

Forces the value v to be within the range from minValue () 到 maxValue () inclusive, and returns the result.

This function is provided so that you can easily force other numbers than value () into the allowed range. You do not need to call it in order to use Q3RangeControl 本身。

另请参阅 setValue (), value (), minValue (),和 maxValue ().

[protected] void Q3RangeControl:: directSetValue ( int value )

Sets the range control value directly without calling valueChange ().

Forces the new value to be within the legal range.

You will rarely have to call this function. However, if you want to change the range control's value inside the overloaded method valueChange (), setValue () would call the function valueChange () again. To avoid this recursion you must use directSetValue() instead.

另请参阅 setValue ().

int Q3RangeControl:: lineStep () const

Returns the line step.

另请参阅 setSteps () 和 pageStep ().

int Q3RangeControl:: maxValue () const

Returns the maximum value of the range.

另请参阅 setMaxValue (), setRange (),和 minValue ().

int Q3RangeControl:: minValue () const

Returns the minimum value of the range.

另请参阅 setMinValue (), setRange (),和 maxValue ().

int Q3RangeControl:: pageStep () const

Returns the page step.

另请参阅 setSteps () 和 lineStep ().

[protected] int Q3RangeControl:: positionFromValue ( int logical_val , int span ) const

转换 logical_val to a pixel position. minValue () maps to 0, maxValue () maps to span 和其它值在之间均匀分布。

This function can handle the entire integer range without overflow, providing span is <= 4096.

Calling this method is useful when actually drawing a range control such as a QScrollBar on-screen.

另请参阅 valueFromPosition ().

[protected] int Q3RangeControl:: prevValue () const

Returns the previous value of the range control. "Previous value" means the value before the last change occurred. Setting a new range may affect the value, too, because the value is forced to be inside the specified range. When the range control is initially created, this is the same as value ().

prevValue() can be outside the current legal range if a call to setRange () causes the current value to change. For example, if the range was [0, 1000] and the current value is 500, setRange (0, 400) makes value () return 400 and prevValue() return 500.

另请参阅 value () 和 setRange ().

[virtual protected] void Q3RangeControl:: rangeChange ()

This virtual function is called whenever the range control's range changes. You can reimplement it if you want to be notified when the range changes. The default implementation does nothing.

Note that this method is called after the range has changed.

另请参阅 setRange (), valueChange (),和 stepChange ().

void Q3RangeControl:: setMaxValue ( int maxVal )

Sets the minimum value of the range to maxVal .

If necessary, the minValue () is adjusted so that the range remains valid.

另请参阅 maxValue () 和 setMinValue ().

void Q3RangeControl:: setMinValue ( int minVal )

Sets the minimum value of the range to minVal .

If necessary, the maxValue () is adjusted so that the range remains valid.

另请参阅 minValue () 和 setMaxValue ().

void Q3RangeControl:: setRange ( int minValue , int maxValue )

Sets the range control's minimum value to minValue and its maximum value to maxValue .

Calls the virtual rangeChange () function if one or both of the new minimum and maximum values are different from the previous setting. Calls the virtual valueChange () function if the current value is adjusted because it was outside the new range.

maxValue 小于 minValue , minValue 变为唯一合法值。

另请参阅 minValue () 和 maxValue ().

void Q3RangeControl:: setSteps ( int lineStep , int pageStep )

Sets the range's line step to lineStep and page step to pageStep .

Calls the virtual stepChange () function if the new line step or page step are different from the previous settings.

另请参阅 lineStep (), pageStep (),和 setRange ().

void Q3RangeControl:: setValue ( int value )

Sets the range control's value to value and forces it to be within the legal range.

Calls the virtual valueChange () function if the new value is different from the previous value. The old value can still be retrieved using prevValue ().

另请参阅 value ().

[virtual protected] void Q3RangeControl:: stepChange ()

This virtual function is called whenever the range control's line or page step settings change. You can reimplement it if you want to be notified when the step changes. The default implementation does nothing.

Note that this method is called after a step setting has changed.

另请参阅 setSteps (), rangeChange (),和 valueChange ().

void Q3RangeControl:: subtractLine ()

相当于 setValue(value() - lineStep()) .

If the value is changed, then valueChange () 被调用。

另请参阅 addLine (), subtractPage (),和 setValue ().

void Q3RangeControl:: subtractPage ()

相当于 setValue(value() - pageStep()) .

If the value is changed, then valueChange () 被调用。

另请参阅 addPage (), subtractLine (),和 setValue ().

int Q3RangeControl:: value () const

Returns the current range control value. This is guaranteed to be within the range [ minValue (), maxValue ()].

另请参阅 setValue () 和 prevValue ().

[virtual protected] void Q3RangeControl:: valueChange ()

This virtual function is called whenever the range control value changes. You can reimplement it if you want to be notified when the value changes. The default implementation does nothing.

Note that this method is called after the value has changed. The previous value can be retrieved using prevValue ().

另请参阅 setValue (), addPage (), subtractPage (), addLine (), subtractLine (), rangeChange (),和 stepChange ().

[protected] int Q3RangeControl:: valueFromPosition ( int pos , int span ) const

Converts the pixel position pos to a value. 0 maps to minValue (), span 映射到 maxValue () and other values are distributed evenly in-between.

此函数可以处理整个整数范围而不溢出。

Calling this method is useful if you actually implemented a range control widget such as QScrollBar and want to handle mouse press events. This function then maps screen coordinates to the logical values.

另请参阅 positionFromValue ().