Results 1 to 4 of 4

Thread: QSpinBox validator problem

  1. #1
    Join Date
    Jun 2008
    Posts
    64
    Thanks
    7
    Qt products
    Qt3 Qt4

    Default QSpinBox validator problem

    In the past(QT3), I can use setValidator() for QSpinBox
    for example,
    QRegExpValidator *rv = new QRegExpValidator( rx, 0);
    spinBox->setValidator( rv );
    However I found that it is not possible to do so when porting to QT4.
    Can anyone tell me what to do?
    thanks

  2. #2
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinBox validator problem

    Hi,
    one possibility is to
    override
    Qt Code:
    1. QValidator::State QAbstractSpinBox::validate ( QString & input, int & pos ) const [virtual]
    To copy to clipboard, switch view to plain text mode 
    and use validator inside.

    Second approach is to get lineedit of a spinbox
    Qt Code:
    1. QLineEdit * QAbstractSpinBox::lineEdit () const [protected]
    To copy to clipboard, switch view to plain text mode 
    an setValidator there
    Qt Code:
    1. void QLineEdit::setValidator ( const QValidator * v )
    To copy to clipboard, switch view to plain text mode 
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  3. #3
    Join Date
    Aug 2011
    Posts
    15
    Thanks
    2

    Default Re: QSpinBox validator problem

    mchara

    lineEdit() function is protected.
    Do you mean it's not possible to set validator for spin box without inheriting it?
    I'm already using QSpinBox class objects everywhere, how should I set validator for those objects?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSpinBox validator problem

    If you're using Designer, you can use the "Promote to" tool available from context menu of items dropped on forms. If you're not using Designer then simply replace instances of QSpinBox with proper subclasses. However I would go for reimplementing validate() rather than trying tricks with spinbox's lineEdit.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QSpinBox or QLabels
    By ToddAtWSU in forum Qt Programming
    Replies: 10
    Last Post: 27th November 2007, 20:10
  2. eventFilter and clicking inside QSpinBox
    By T4ng10r in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2007, 21:02
  3. QSpinBox with checkbox
    By :db:sStrong in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2007, 13:22
  4. float value to Qspinbox
    By nErnie in forum Qt Programming
    Replies: 6
    Last Post: 17th October 2006, 08:16
  5. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.