JKQtExtras
a library of useful Qt widgets and tools
JKQTEDoubleEdit Class Reference

this QLineEdit descendent implements a validating edit field that allows to enter floating point numbers with a possibly defined range More...

#include <jkqtedoubleedit.h>

Inheritance diagram for JKQTEDoubleEdit:
Collaboration diagram for JKQTEDoubleEdit:

Public Slots

void setBackgroundColor (const QColor &color)
 color for the widget's background More...
 
void setCheckBounds (bool min, bool max)
 sets which bounds of the range to checked More...
 
void setCheckMaximum (bool check)
 sets whether the range maximum is checked More...
 
void setCheckMinimum (bool check)
 sets whether the range minimum is checked More...
 
void setDecimals (int decimals)
 set the number of displayed decimals More...
 
void setErrorBackgroundColor (const QColor &color)
 background color used when an entry error occured (unparseable string) More...
 
void setIncrement (double inc)
 increment, when using the buttons or up/down keys More...
 
void setIntegerWidget (bool intWidget)
 en-/disable integer edit mode (only integer numbers are allowed, i.e. no decimals!) More...
 
void setMaximum (double value)
 maximum of the value range, also calls setCheckMaximum(true) More...
 
void setMinimum (double value)
 minimum of the value range, also calls setCheckMinimum(true) More...
 
void setNoIntegerBackgroundColor (const QColor &noIntegerBackgroundColor)
 background color used when an setIntegerWidget(true), but the entered number is no integer More...
 
void setRange (double min, double max)
 set the value range, also calls setCheckMaximum(true) and setCheckMinimum(true) More...
 
void setShowUpDown (bool showUpDown)
 sets whether up/down buttons are shown More...
 
void setSingleStep (double inc)
 sets the single step increment (equivalent to setIncrement(inc) ) More...
 
void setValue (double value)
 set the value entered in this widget More...
 
void stepDown ()
 decrease value by increment() More...
 
void stepUp ()
 increase value by increment() More...
 

Signals

void focusOut (double value)
 emitted when the widget looses focus More...
 
void keyEventMatches (int key, Qt::KeyboardModifiers modifiers)
 emitted when a key event matches More...
 
void valueChanged (double value)
 emited whenever a entered value changed More...
 

Public Member Functions

 JKQTEDoubleEdit (QWidget *parent)
 class constructor More...
 
virtual ~JKQTEDoubleEdit ()
 class destructor More...
 
void addContextmenuAction (QAction *menuAction)
 add a new QAction to the default context menu (append after a seprator) More...
 
void addKeyEvent (int key, Qt::KeyboardModifiers modifiers)
 add a new Key Event More...
 
QColor backgroundColor () const
 color for the widget's background More...
 
bool checkMaximum () const
 returns whether the range maximum is checked More...
 
bool checkMinimum () const
 returns whether the range minimum is checked More...
 
void clearContextmenuActions ()
 remove all additional context menu QAction s More...
 
int decimals () const
 returns the number of displayed decimals More...
 
void deleteContextmenuAction (QAction *menuAction)
 remove a given QAction from the default context menu (added with addContextmenuAction() ) More...
 
QColor errorBackgroundColor () const
 background color used when an entry error occured (unparseable string) More...
 
double increment () const
 increment, when using the buttons or up/down keys More...
 
bool isIntegerWidget () const
 is integer edit mode en-/disable (only integer numbers are allowed, i.e. no decimals!) More...
 
double maximum () const
 maximum of the value range More...
 
double minimum () const
 minimum of the value range More...
 
QColor noIntegerBackgroundColor () const
 background color used when an setIntegerWidget(true), but the entered number is no integer More...
 
bool showUpDown () const
 are the up/down buttons shown? More...
 
double value () const
 return the value entered in this widget More...
 

Protected Slots

virtual void focusOutEvent (QFocusEvent *event)
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void resizeEvent (QResizeEvent *event)
 
void updateWidget (const QString &text)
 
virtual void wheelEvent (QWheelEvent *event)
 

Protected Member Functions

virtual void contextMenuEvent (QContextMenuEvent *event)
 
void setValidator (const QValidator *validator)
 hidden setValidator() method More...
 

Protected Attributes

QString JKDoubleEdit_BASIC_REGEXP
 
QColor m_background
 
QToolButton * m_btnDown
 
QToolButton * m_btnUp
 
bool m_checkMaximum
 
bool m_checkMinimum
 
QList< QAction * > m_contextmenuActions
 list of additional actions for context menu More...
 
double m_current
 
int m_decimals
 
QColor m_errorColor
 error color More...
 
double m_increment
 
bool m_Integer
 
QList< QPair< int, Qt::KeyboardModifiers > > m_keyEvents
 used to store the key events More...
 
double m_maximum
 
double m_minimum
 
QColor m_noIntegerBackgroundColor
 
QRegExp m_regexp
 regular expression used to match floating point numbers More...
 
bool m_showUpDown
 
QRegExpValidator * m_validator
 RegExp validator for this widget. More...
 

Properties

QColor backgroundColor
 
bool checkMaximum
 
bool checkMinimum
 
int decimals
 
QColor errorBackgroundColor
 
double increment
 
bool integerWidget
 
double maximum
 
double minimum
 
QColor noIntegerBackgroundColor
 
bool showUpDown
 
double value
 

Detailed Description

this QLineEdit descendent implements a validating edit field that allows to enter floating point numbers with a possibly defined range

This widget supports this set of features:

  • This widget accepts input in standard and scientific notation.
  • The widget can optionally check (and correct) the edit range. Checking can be switched for the upper and lower bound indepently!
  • The maximal number of decimals may be set using setDecimals().
    Note
    Note that trailing 0s are deleted from the string.
  • This widget accepts comma and point as decimal separator and transforms them to the systems decimal separator, set in the current locale.
  • This widget colors the background of the widget if the number you entered exceeds the range. In that case the edit corrects the value when it looses its focus. The error background color may be set by setErrorBackgroundColor().
  • It is also possible to extend the default context menu with new QAction's by calling addContextmenuAction(), deleteContextmenuAction() and clearContextmenuActions().
  • This widget may also be used to catch key events. You will have to register each event using addKeyEvent(). If a key event matches, the keyEvent() signal will be emitted.

Screenshot:

Basic usage is simple:

JKQTEDoubleEdit* dblEdit=new JKQTEDoubleEdit(wid);
// set number range
dblEdit->setRange(-10,10);
// set to check upper and lower range bounds
dblEdit->setCheckBounds(true, true);
// set number of decimals
dblEdit->setDecimals(2);
// set a value
dblEdit->setValue(3.1415);
// set background color for OK-values and error values
dblEdit->setBackgroundColor(QColor("lime"));
dblEdit->setErrorBackgroundColor(QColor("salmon"));
// set up/down buttons visible
dblEdit->setShowUpDown(true);

Constructor & Destructor Documentation

◆ JKQTEDoubleEdit()

JKQTEDoubleEdit::JKQTEDoubleEdit ( QWidget *  parent)

class constructor

◆ ~JKQTEDoubleEdit()

virtual JKQTEDoubleEdit::~JKQTEDoubleEdit ( )
virtual

class destructor

Member Function Documentation

◆ addContextmenuAction()

void JKQTEDoubleEdit::addContextmenuAction ( QAction *  menuAction)

add a new QAction to the default context menu (append after a seprator)

◆ addKeyEvent()

void JKQTEDoubleEdit::addKeyEvent ( int  key,
Qt::KeyboardModifiers  modifiers 
)

add a new Key Event

◆ backgroundColor()

QColor JKQTEDoubleEdit::backgroundColor ( ) const

color for the widget's background

◆ checkMaximum()

bool JKQTEDoubleEdit::checkMaximum ( ) const

returns whether the range maximum is checked

◆ checkMinimum()

bool JKQTEDoubleEdit::checkMinimum ( ) const

returns whether the range minimum is checked

◆ clearContextmenuActions()

void JKQTEDoubleEdit::clearContextmenuActions ( )

remove all additional context menu QAction s

◆ contextMenuEvent()

virtual void JKQTEDoubleEdit::contextMenuEvent ( QContextMenuEvent *  event)
protectedvirtual

◆ decimals()

int JKQTEDoubleEdit::decimals ( ) const

returns the number of displayed decimals

◆ deleteContextmenuAction()

void JKQTEDoubleEdit::deleteContextmenuAction ( QAction *  menuAction)

remove a given QAction from the default context menu (added with addContextmenuAction() )

◆ errorBackgroundColor()

QColor JKQTEDoubleEdit::errorBackgroundColor ( ) const

background color used when an entry error occured (unparseable string)

◆ focusOut

void JKQTEDoubleEdit::focusOut ( double  value)
signal

emitted when the widget looses focus

◆ focusOutEvent

virtual void JKQTEDoubleEdit::focusOutEvent ( QFocusEvent *  event)
protectedvirtualslot

◆ increment()

double JKQTEDoubleEdit::increment ( ) const

increment, when using the buttons or up/down keys

◆ isIntegerWidget()

bool JKQTEDoubleEdit::isIntegerWidget ( ) const

is integer edit mode en-/disable (only integer numbers are allowed, i.e. no decimals!)

◆ keyEventMatches

void JKQTEDoubleEdit::keyEventMatches ( int  key,
Qt::KeyboardModifiers  modifiers 
)
signal

emitted when a key event matches

◆ keyPressEvent

virtual void JKQTEDoubleEdit::keyPressEvent ( QKeyEvent *  event)
protectedvirtualslot

◆ maximum()

double JKQTEDoubleEdit::maximum ( ) const

maximum of the value range

◆ minimum()

double JKQTEDoubleEdit::minimum ( ) const

minimum of the value range

◆ noIntegerBackgroundColor()

QColor JKQTEDoubleEdit::noIntegerBackgroundColor ( ) const

background color used when an setIntegerWidget(true), but the entered number is no integer

◆ resizeEvent

virtual void JKQTEDoubleEdit::resizeEvent ( QResizeEvent *  event)
protectedvirtualslot

◆ setBackgroundColor

void JKQTEDoubleEdit::setBackgroundColor ( const QColor &  color)
slot

color for the widget's background

◆ setCheckBounds

void JKQTEDoubleEdit::setCheckBounds ( bool  min,
bool  max 
)
slot

sets which bounds of the range to checked

◆ setCheckMaximum

void JKQTEDoubleEdit::setCheckMaximum ( bool  check)
slot

sets whether the range maximum is checked

◆ setCheckMinimum

void JKQTEDoubleEdit::setCheckMinimum ( bool  check)
slot

sets whether the range minimum is checked

◆ setDecimals

void JKQTEDoubleEdit::setDecimals ( int  decimals)
slot

set the number of displayed decimals

◆ setErrorBackgroundColor

void JKQTEDoubleEdit::setErrorBackgroundColor ( const QColor &  color)
slot

background color used when an entry error occured (unparseable string)

◆ setIncrement

void JKQTEDoubleEdit::setIncrement ( double  inc)
slot

increment, when using the buttons or up/down keys

◆ setIntegerWidget

void JKQTEDoubleEdit::setIntegerWidget ( bool  intWidget)
slot

en-/disable integer edit mode (only integer numbers are allowed, i.e. no decimals!)

◆ setMaximum

void JKQTEDoubleEdit::setMaximum ( double  value)
slot

maximum of the value range, also calls setCheckMaximum(true)

◆ setMinimum

void JKQTEDoubleEdit::setMinimum ( double  value)
slot

minimum of the value range, also calls setCheckMinimum(true)

◆ setNoIntegerBackgroundColor

void JKQTEDoubleEdit::setNoIntegerBackgroundColor ( const QColor &  noIntegerBackgroundColor)
slot

background color used when an setIntegerWidget(true), but the entered number is no integer

◆ setRange

void JKQTEDoubleEdit::setRange ( double  min,
double  max 
)
slot

set the value range, also calls setCheckMaximum(true) and setCheckMinimum(true)

◆ setShowUpDown

void JKQTEDoubleEdit::setShowUpDown ( bool  showUpDown)
slot

sets whether up/down buttons are shown

◆ setSingleStep

void JKQTEDoubleEdit::setSingleStep ( double  inc)
slot

sets the single step increment (equivalent to setIncrement(inc) )

◆ setValidator()

void JKQTEDoubleEdit::setValidator ( const QValidator *  validator)
protected

hidden setValidator() method

◆ setValue

void JKQTEDoubleEdit::setValue ( double  value)
slot

set the value entered in this widget

◆ showUpDown()

bool JKQTEDoubleEdit::showUpDown ( ) const

are the up/down buttons shown?

◆ stepDown

void JKQTEDoubleEdit::stepDown ( )
slot

decrease value by increment()

◆ stepUp

void JKQTEDoubleEdit::stepUp ( )
slot

increase value by increment()

◆ updateWidget

void JKQTEDoubleEdit::updateWidget ( const QString &  text)
protectedslot

◆ value()

double JKQTEDoubleEdit::value ( ) const

return the value entered in this widget

◆ valueChanged

void JKQTEDoubleEdit::valueChanged ( double  value)
signal

emited whenever a entered value changed

◆ wheelEvent

virtual void JKQTEDoubleEdit::wheelEvent ( QWheelEvent *  event)
protectedvirtualslot

Member Data Documentation

◆ JKDoubleEdit_BASIC_REGEXP

QString JKQTEDoubleEdit::JKDoubleEdit_BASIC_REGEXP
protected

◆ m_background

QColor JKQTEDoubleEdit::m_background
protected

◆ m_btnDown

QToolButton* JKQTEDoubleEdit::m_btnDown
protected

◆ m_btnUp

QToolButton* JKQTEDoubleEdit::m_btnUp
protected

◆ m_checkMaximum

bool JKQTEDoubleEdit::m_checkMaximum
protected

◆ m_checkMinimum

bool JKQTEDoubleEdit::m_checkMinimum
protected

◆ m_contextmenuActions

QList<QAction*> JKQTEDoubleEdit::m_contextmenuActions
protected

list of additional actions for context menu

◆ m_current

double JKQTEDoubleEdit::m_current
protected

◆ m_decimals

int JKQTEDoubleEdit::m_decimals
protected

◆ m_errorColor

QColor JKQTEDoubleEdit::m_errorColor
protected

error color

◆ m_increment

double JKQTEDoubleEdit::m_increment
protected

◆ m_Integer

bool JKQTEDoubleEdit::m_Integer
protected

◆ m_keyEvents

QList<QPair<int, Qt::KeyboardModifiers> > JKQTEDoubleEdit::m_keyEvents
protected

used to store the key events

◆ m_maximum

double JKQTEDoubleEdit::m_maximum
protected

◆ m_minimum

double JKQTEDoubleEdit::m_minimum
protected

◆ m_noIntegerBackgroundColor

QColor JKQTEDoubleEdit::m_noIntegerBackgroundColor
protected

◆ m_regexp

QRegExp JKQTEDoubleEdit::m_regexp
protected

regular expression used to match floating point numbers

◆ m_showUpDown

bool JKQTEDoubleEdit::m_showUpDown
protected

◆ m_validator

QRegExpValidator* JKQTEDoubleEdit::m_validator
protected

RegExp validator for this widget.

Property Documentation

◆ backgroundColor

QColor JKQTEDoubleEdit::backgroundColor
readwrite

◆ checkMaximum

bool JKQTEDoubleEdit::checkMaximum
readwrite

◆ checkMinimum

bool JKQTEDoubleEdit::checkMinimum
readwrite

◆ decimals

int JKQTEDoubleEdit::decimals
readwrite

◆ errorBackgroundColor

QColor JKQTEDoubleEdit::errorBackgroundColor
readwrite

◆ increment

double JKQTEDoubleEdit::increment
readwrite

◆ integerWidget

bool JKQTEDoubleEdit::integerWidget
readwrite

◆ maximum

double JKQTEDoubleEdit::maximum
readwrite

◆ minimum

double JKQTEDoubleEdit::minimum
readwrite

◆ noIntegerBackgroundColor

QColor JKQTEDoubleEdit::noIntegerBackgroundColor
readwrite

◆ showUpDown

bool JKQTEDoubleEdit::showUpDown
readwrite

◆ value

double JKQTEDoubleEdit::value
readwrite

The documentation for this class was generated from the following file:
JKQTEDoubleEdit::setDecimals
void setDecimals(int decimals)
set the number of displayed decimals
JKQTEDoubleEdit::setCheckBounds
void setCheckBounds(bool min, bool max)
sets which bounds of the range to checked
JKQTEDoubleEdit::setRange
void setRange(double min, double max)
set the value range, also calls setCheckMaximum(true) and setCheckMinimum(true)
JKQTEDoubleEdit::setErrorBackgroundColor
void setErrorBackgroundColor(const QColor &color)
background color used when an entry error occured (unparseable string)
JKQTEDoubleEdit::setBackgroundColor
void setBackgroundColor(const QColor &color)
color for the widget's background
JKQTEDoubleEdit::JKQTEDoubleEdit
JKQTEDoubleEdit(QWidget *parent)
class constructor
JKQTEDoubleEdit::setValue
void setValue(double value)
set the value entered in this widget
JKQTEDoubleEdit::setShowUpDown
void setShowUpDown(bool showUpDown)
sets whether up/down buttons are shown
JKQTEDoubleEdit
this QLineEdit descendent implements a validating edit field that allows to enter floating point numb...
Definition: jkqtedoubleedit.h:58