Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QRangeControl Class Reference


The QRangeControl class provides an integer value within a range. More...

#include <qrangecontrol.h>

Inherited by QDial, QScrollBar, QSlider and QSpinBox.

List of all member functions.

Public Members

Protected Members


Detailed Description

The QRangeControl class provides an integer value within a range.

It was originally designed for the QScrollBar widget, but it can also be practical for other purposes such as QSlider and QSpinBox. Here are the five main concepts in the class:

  • The current value. This is the bounded integer that QRangeControl maintains. value() returns this, and several functions including setValue() set it.
  • The minimum. This is the lowest value value() can ever return. Returned by minValue(), set by setRange() or one of the constructors.
  • The maximum. This is the highest value value() can ever return. Returned by maxValue(), set by setRange() or one of the constructors.
  • The line step. This is the smaller of two natural steps QRangeControl provides, and typically corresponds to the user pressing an arrow key. The line step is returned by lineStep() and set using setSteps(). The functions addLine() and subtractLine() allow easy movement of the current value by lineStep().
  • The page step. This is the larger of two natural steps QRangeControl provides, and typically corresponds to the user pressing one of the PageUp and PageDown keys. The page step is returned by pageStep() and set using setSteps(). The functions addPage() and substractPage() allow easy movement of the current value by pageStep().

Note that 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 just minValue()+n*lineStep() for integer values of n. Some widgets may allow the user to set any value at all, others may just provide multiples of lineStep()/pageStep().

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

Finally, QRangeControl 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, which inherit QRangeControl, provide at least a signal called valueChanged(), and many widgets will want to provide addStep(), addPage(), substractStep() and substractPage() as slots.

Note that you have to use multiple inheritance if you plan to implement a widget using QRangeControl, since QRangeControl is not derived from QWidget.


Member Function Documentation

QRangeControl::QRangeControl ()

Constructs a range control with min value 0, max value 99, line step 1, page step 10 and initial value 0.

QRangeControl::QRangeControl ( 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.

value is forced to be within the legal range using the bound() method.

void QRangeControl::addLine ()

Equivalent to

 setValue( value()+lineStep() )
plus a test for numerical overflow

If the value is changed, then valueChange() is called.

See also subtractLine(), addPage() and setValue().

void QRangeControl::addPage ()

Equivalent to

 setValue( value()+pageStep() )
plus a test for numerical overflow.

If the value is changed, then valueChange() is called.

See also subtractPage(), addLine() and setValue().

int QRangeControl::bound ( int v ) const

Forces v to be within the range from minValue() to 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 QRangeControl itself.

See also setValue(), value(), minValue() and maxValue().

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

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

Forces the new value to be within the legal range.

You will find few cases only where you have to call this function. However, if you want to change the range controls value inside the overloaded method valueChange() then setValue() would call the function valueChange() again. To avoid this recursion you must use directSetValue() instead.

See also setValue().

int QRangeControl::lineStep () const

Returns the current line step.

See also setSteps() and pageStep().

int QRangeControl::maxValue () const

Returns the current maximum value of the range.

See also setRange() and minValue().

int QRangeControl::minValue () const

Returns the current minimum value of the range.

See also setRange() and maxValue().

int QRangeControl::pageStep () const

Returns the current page step.

See also setSteps() and lineStep().

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

Converts logical_val to a pixel position. minValue() maps to 0, maxValue() maps to span, and other values are distributed evenly in between.

This function can handle the entire integer range without overflow.

Callings this method is useful when actually drawing a range control like a QScrollBar on the screen.

See also valueFromPosition().

int QRangeControl::prevValue () const [protected]

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, since the value is forced to be inside the specified range. When the range control is initially created, this is the same as value().

Note that 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 500, setRange( 0, 400 ) makes value() return 400 and prevValue() 500)

See also value() and setRange().

void QRangeControl::rangeChange () [virtual protected]

This virtual function is called whenever the range controls 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 changed.

See also setRange(), valueChange() and stepChange().

Reimplemented in QSlider, QScrollBar and QDial.

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

Sets the range min value to minValue and the max value to maxValue.

Calls the virtual rangeChange() function if one or both of the new min and max 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.

If maxValue is smaller than minValue, minValue becomes the only legal value.

See also minValue() and maxValue().

Examples: xform/xform.cpp

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

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

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

See also lineStep(), pageStep() and setRange().

void QRangeControl::setValue ( int value )

Sets the range controls 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().

See also value().

void QRangeControl::stepChange () [virtual protected]

This virtual function is called whenever the range controls line/page step settings changes. 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 the step settings changed.

See also setSteps(), rangeChange() and valueChange().

Reimplemented in QScrollBar.

void QRangeControl::subtractLine ()

Equivalent to

 setValue( value()-lineStep() )
plus a test for numerical underflow

If the value is changed, then valueChange() is called.

See also addLine(), subtractPage() and setValue().

void QRangeControl::subtractPage ()

Equivalent to

 setValue( value()-pageStep() )
plus a test for numerical underflow

If the value is changed, then valueChange() is called.

See also addPage(), subtractLine() and setValue().

int QRangeControl::value () const

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

See also setValue() and prevValue().

void QRangeControl::valueChange () [virtual protected]

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 changed. The previous value can be retrieved using prevValue().

See also setValue(), addPage(), subtractPage(), addLine(), subtractLine(), rangeChange() and stepChange().

Reimplemented in QScrollBar, QDial and QSlider.

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

Converts the pixel position pos to a value. 0 maps to minValue(), span maps to maxValue(), 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 like QScrollBar and want to handle mouse press events. This function maps then screen coordinates to the logical values.

See also positionFromValue().


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 2.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web