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  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QAbstractSpinBox Class Reference
[QtGui module]

The QAbstractSpinBox class provides a spinbox and a line edit to display values. More...

#include <QAbstractSpinBox>

Inherits QWidget.

Inherited by QDateTimeEdit, QDoubleSpinBox, and QSpinBox.

Public Types

Properties

  • 54 properties inherited from QWidget
  • 1 property inherited from QObject

Public Functions

  • 190 public functions inherited from QWidget
  • 28 public functions inherited from QObject
  • 12 public functions inherited from QPaintDevice

Public Slots

  • 17 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

Protected Functions

  • 39 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 4 static public members inherited from QObject

Detailed Description

The QAbstractSpinBox class provides a spinbox and a line edit to display values.

The class is designed as a common super class for widgets like QSpinBox, QDoubleSpinBox and QDateTimeEdit

Here are the main properties of the class:

  1. text: The text that is displayed in the QAbstractSpinBox.
  2. alignment: The alignment of the text in the QAbstractSpinBox.
  3. wrapping: Whether the QAbstractSpinBox wraps from the minimum value to the maximum value and vica versa.

QAbstractSpinBox provides a virtual stepBy() function that is called whenever the user triggers a step. This function takes an integer value to signify how many steps were taken. E.g. Pressing Qt::Key_Down will trigger a call to stepBy(-1).

QAbstractSpinBox also provide a virtual function stepEnabled() to determine whether stepping up/down is allowed at any point. This function returns a bitset of StepEnabled.


Member Type Documentation

enum QAbstractSpinBox::ButtonSymbols

This enum type describes the symbols that can be displayed on the buttons in a spin box.

ConstantValueDescription
QAbstractSpinBox::UpDownArrows0Little arrows in the classic style.
QAbstractSpinBox::PlusMinus1+ and - symbols.

See also QAbstractSpinBox::buttonSymbols.

enum QAbstractSpinBox::StepEnabledFlag
flags QAbstractSpinBox::StepEnabled

ConstantValue
QAbstractSpinBox::StepNone0x00
QAbstractSpinBox::StepUpEnabled0x01
QAbstractSpinBox::StepDownEnabled0x02

The StepEnabled type is a typedef for QFlags<StepEnabledFlag>. It stores an OR combination of StepEnabledFlag values.


Property Documentation

alignment : Qt::Alignment

This property holds the alignment of the spin box.

Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter.

By default, the alignment is Qt::AlignLeft

Attempting to set the alignment to an illegal flag combination does nothing.

Access functions:

  • Qt::Alignment alignment () const
  • void setAlignment ( Qt::Alignment flag )

See also Qt::Alignment.

buttonSymbols : ButtonSymbols

This property holds the current button symbol mode.

The possible values can be either UpDownArrows or PlusMinus. The default is UpDownArrows.

Access functions:

  • ButtonSymbols buttonSymbols () const
  • void setButtonSymbols ( ButtonSymbols bs )

See also ButtonSymbols.

frame : bool

This property holds whether the spin box draws itself with a frame.

If enabled (the default) the spin box draws itself inside a frame, otherwise the spin box draws itself without any frame.

Access functions:

  • bool hasFrame () const
  • void setFrame ( bool )

readOnly : bool

This property holds whether the spin box is read only.

In read-only mode, the user can still copy the text to the clipboard, or drag and drop the text; but cannot edit it.

The QLineEdit in the QAbstractSpinBox does not show a cursor in read-only mode.

Access functions:

  • bool isReadOnly () const
  • void setReadOnly ( bool r )

See also QLineEdit::readOnly.

specialValueText : QString

This property holds the special-value text.

If set, the spin box will display this text instead of a numeric value whenever the current value is equal to minimum(). Typical use is to indicate that this choice has a special (default) meaning.

For example, if your spin box allows the user to choose the margin width in a print dialog and your application is able to automatically choose a good margin width, you can set up the spin box like this:

    QSpinBox marginBox(-1, 20, 1, parent);
    marginBox.setSuffix(" mm");
    marginBox.setSpecialValueText("Auto");

The user will then be able to choose a margin width from 0-20 millimeters or select "Auto" to leave it to the application to choose. Your code must then interpret the spin box value of -1 as the user requesting automatic margin width.

All values are displayed with the prefix and suffix (if set), except for the special value, which only shows the special value text.

To turn off the special-value text display, call this function with an empty string. The default is no special-value text, i.e. the numeric value is shown as usual.

If no special-value text is set, specialValueText() returns an empty string.

Access functions:

  • QString specialValueText () const
  • void setSpecialValueText ( const QString & s )

text : const QString

This property holds the spin box's text, including any prefix and suffix.

There is no default text.

Access functions:

  • QString text () const

wrapping : bool

This property holds whether the spin box is circular.

If wrapping is true stepping up from maximum() value will take you to the minimum() value and vica versa. Wrapping only make sense if you have minimum() and maximum() values set.

    QSpinBox *spinBox = new QSpinBox(this);
    spinBox->setRange(0, 100);
    spinBox->setWrapping(true);
    sb->setValue(100);
    sb->stepBy(1);
    // value is 0

By default, wrapping is turned off.

Access functions:

  • bool wrapping () const
  • void setWrapping ( bool w )

See also QSpinBox::minimum() and QSpinBox::maximum().


Member Function Documentation

QAbstractSpinBox::QAbstractSpinBox ( QWidget * parent = 0 )

Constructs an abstract spinbox with the given parent with default wrapping, and alignment properties.

QAbstractSpinBox::~QAbstractSpinBox ()

Called when the QAbstractSpinBox is destroyed.

void QAbstractSpinBox::clear ()   [virtual slot]

Clears the lineedit of all text but prefix and suffix.

void QAbstractSpinBox::editingFinished ()   [signal]

This signal is emitted editing is finished. This happens when the spinbox loses focus and when enter is pressed.

void QAbstractSpinBox::fixup ( QString & input ) const   [virtual]

This virtual function is called by the QAbstractSpinBox if the input is not validated to QValidator::Acceptable when Return is pressed or interpretText() is called. It will try to change the text so it is valid. Reimplemented in the various subclasses.

void QAbstractSpinBox::interpretText ()

This function interprets the text of the spin box. If the value has changed since last interpretation it will emit signals.

QLineEdit * QAbstractSpinBox::lineEdit () const   [protected]

This function returns a pointer to the line edit of the spin box.

See also setLineEdit().

void QAbstractSpinBox::selectAll ()   [slot]

Selects all the text in the spinbox except the prefix and suffix.

void QAbstractSpinBox::setLineEdit ( QLineEdit * lineEdit )   [protected]

Sets the line edit of the spinbox to be lineEdit instead of the current line edit widget. lineEdit can not be 0.

QAbstractSpinBox takes ownership of the new lineEdit

If QLineEdit::validator() for the lineEdit returns 0, the internal validator of the spinbox will be set on the line edit.

See also lineEdit().

void QAbstractSpinBox::stepBy ( int steps )   [virtual]

Virtual function that is called whenever the user triggers a step. The steps parameter indicates how many steps were taken, e.g. Pressing Qt::Key_Down will trigger a call to stepBy(-1), whereas pressing Qt::Key_Prior will trigger a call to stepBy(10).

If you subclass QAbstractSpinBox you must reimplement this function. Note that this function is called even if the resulting value will be outside the bounds of minimum and maximum. It's this function's job to handle these situations.

void QAbstractSpinBox::stepDown ()   [slot]

Steps down by one linestep Calling this slot is analogous to calling stepBy(-1);

See also stepBy() and stepUp().

StepEnabled QAbstractSpinBox::stepEnabled () const   [virtual protected]

Virtual function that determines whether stepping up and down is legal at any given time.

The up arrow will be painted as disabled unless (stepEnabled() & StepUpEnabled) != 0.

The default implementation will return (StepUpEnabled| StepDownEnabled) if wrapping is turned on. Else it will return StepDownEnabled if value is > minimum() or'ed with StepUpEnabled if value < maximum().

If you subclass QAbstractSpinBox you will need to reimplement this function.

See also QSpinBox::minimum(), QSpinBox::maximum(), and wrapping().

void QAbstractSpinBox::stepUp ()   [slot]

Steps up by one linestep Calling this slot is analogous to calling stepBy(1);

See also stepBy() and stepDown().

QValidator::State QAbstractSpinBox::validate ( QString & input, int & pos ) const   [virtual]

This virtual function is called by the QAbstractSpinBox to determine whether input is valid. The pos parameter indicates the position in the string. Reimplemented in the various subclasses.

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 85
  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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 19
  7. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. 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 4.1
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