Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

  • Qt 4.8
  • Qt3SupportLight
  • Q3RangeControl

Q3RangeControl Class

TheQ3RangeControl class provides an integer value within a range.More...

Header:#include <Q3RangeControl>

Public Functions

Q3RangeControl()
Q3RangeControl(int minValue, int maxValue, int lineStep, int pageStep, int value)
virtual~Q3RangeControl()
voidaddLine()
voidaddPage()
intbound(int v) const
intlineStep() const
intmaxValue() const
intminValue() const
intpageStep() const
voidsetMaxValue(int maxVal)
voidsetMinValue(int minVal)
voidsetRange(int minValue, int maxValue)
voidsetSteps(int lineStep, int pageStep)
voidsetValue(int value)
voidsubtractLine()
voidsubtractPage()
intvalue() const

Protected Functions

voiddirectSetValue(int value)
intpositionFromValue(int logical_val, int span) const
intprevValue() const
virtual voidrangeChange()
virtual voidstepChange()
virtual voidvalueChange()
intvalueFromPosition(int pos, int span) const

Detailed Description

TheQ3RangeControl class provides an integer value within a range.

Although originally designed for theQScrollBar widget, theQ3RangeControl can also be used in conjunction with other widgets such asQSlider andQSpinBox. Here are the five main concepts in the class:

  1. Current value The bounded integer thatQ3RangeControl maintains.value() returns it, and several functions, includingsetValue(), set it.
  2. Minimum The lowest value thatvalue() can ever return. Returned byminValue() and set bysetRange() or one of the constructors.
  3. Maximum The highest value thatvalue() can ever return. Returned bymaxValue() and set bysetRange() or one of the constructors.
  4. Line step The smaller of two natural steps thatQ3RangeControl provides and typically corresponds to the user pressing an arrow key. The line step is returned bylineStep() and set usingsetSteps(). The functionsaddLine() andsubtractLine() respectively increment and decrement the current value bylineStep().
  5. Page step The larger of two natural steps thatQ3RangeControl provides and typically corresponds to the user pressing PageUp or PageDown. The page step is returned bypageStep() and set usingsetSteps(). The functionsaddPage() and substractPage() respectively increment and decrement the current value bypageStep().

Unity (1) may be viewed as a third step size.setValue() lets you set the current value to any integer in the allowed range, not justminValue() +n *lineStep() for integer values ofn. Some widgets may allow the user to set any value at all; others may just provide multiples oflineStep() orpageStep().

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

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

We recommend that all widgets that inheritQ3RangeControl 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 usingQ3RangeControl becauseQ3RangeControl is not derived fromQWidget.

Member Function Documentation

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 thanminValue or greater thanmaxValue, whose line step size islineStep and page step size ispageStep and whose value is initiallyvalue (which is guaranteed to be in range usingbound()).

[virtual]Q3RangeControl::~Q3RangeControl()

Destroys the range control

void Q3RangeControl::addLine()

Equivalent tosetValue(value() + lineStep()).

If the value is changed, thenvalueChange() is called.

See alsosubtractLine(),addPage(), andsetValue().

void Q3RangeControl::addPage()

Equivalent tosetValue(value() + pageStep()).

If the value is changed, thenvalueChange() is called.

See alsosubtractPage(),addLine(), andsetValue().

int Q3RangeControl::bound(int v) const

Forces the valuev to be within the range fromminValue() tomaxValue() inclusive, and returns the result.

This function is provided so that you can easily force other numbers thanvalue() into the allowed range. You do not need to call it in order to useQ3RangeControl itself.

See alsosetValue(),value(),minValue(), andmaxValue().

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

Sets the range controlvalue directly without callingvalueChange().

Forces the newvalue 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 methodvalueChange(),setValue() would call the functionvalueChange() again. To avoid this recursion you must use directSetValue() instead.

See alsosetValue().

int Q3RangeControl::lineStep() const

Returns the line step.

See alsosetSteps() andpageStep().

int Q3RangeControl::maxValue() const

Returns the maximum value of the range.

See alsosetMaxValue(),setRange(), andminValue().

int Q3RangeControl::minValue() const

Returns the minimum value of the range.

See alsosetMinValue(),setRange(), andmaxValue().

int Q3RangeControl::pageStep() const

Returns the page step.

See alsosetSteps() andlineStep().

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

Convertslogical_val to a pixel position.minValue() maps to 0,maxValue() maps tospan and other values are distributed evenly in-between.

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

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

See alsovalueFromPosition().

[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 asvalue().

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

See alsovalue() andsetRange().

[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.

See alsosetRange(),valueChange(), andstepChange().

void Q3RangeControl::setMaxValue(int maxVal)

Sets the minimum value of the range tomaxVal.

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

See alsomaxValue() andsetMinValue().

void Q3RangeControl::setMinValue(int minVal)

Sets the minimum value of the range tominVal.

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

See alsominValue() andsetMaxValue().

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

Sets the range control's minimum value tominValue and its maximum value tomaxValue.

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

IfmaxValue is smaller thanminValue,minValue becomes the only legal value.

See alsominValue() andmaxValue().

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

Sets the range's line step tolineStep and page step topageStep.

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

See alsolineStep(),pageStep(), andsetRange().

void Q3RangeControl::setValue(int value)

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

Calls the virtualvalueChange() function if the new value is different from the previous value. The old value can still be retrieved usingprevValue().

See alsovalue().

[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.

See alsosetSteps(),rangeChange(), andvalueChange().

void Q3RangeControl::subtractLine()

Equivalent tosetValue(value() - lineStep()).

If the value is changed, thenvalueChange() is called.

See alsoaddLine(),subtractPage(), andsetValue().

void Q3RangeControl::subtractPage()

Equivalent tosetValue(value() - pageStep()).

If the value is changed, thenvalueChange() is called.

See alsoaddPage(),subtractLine(), andsetValue().

int Q3RangeControl::value() const

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

See alsosetValue() andprevValue().

[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 usingprevValue().

See alsosetValue(),addPage(),subtractPage(),addLine(),subtractLine(),rangeChange(), andstepChange().

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

Converts the pixel positionpos to a value. 0 maps tominValue(),span maps tomaxValue() and other values are distributed evenly in-between.

This function can handle the entire integer range without overflow.

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

See alsopositionFromValue().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp