Results 1 to 3 of 3

Thread: QValidator problem

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QValidator problem

    Hi,

    myLineEdit->setValidator( new QDoubleValidator(0.0, 512.0, 1, this));

    when I do the above, firstly it doesn't to the correct range check ( i.e. it accepts 717) and secondly I can't edit myLineEdit again after I pressed enter.

    Any ideas?

    Thanks in advance

  2. #2
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QValidator problem

    Old topic, but I have a similar issue. I did a lot of trolling but couldn't find anything.

    With mine it allows you to type 9.00

    I think your supposed to use QValidate::fixUp(), but I am unsure on how to do this.

    Qt Code:
    1. QWidget* StringDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &,const QModelIndex &) const
    2. {
    3. QLineEdit *editor = new QLineEdit(parent);
    4. QDoubleValidator* val = new QDoubleValidator(editor);
    5.  
    6. val->setNotation(QDoubleValidator::StandardNotation);
    7. val->setRange(0, 5.1, 2);
    8. editor->setValidator(val);
    9.  
    10. return editor;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Anyone got some tips please?

  3. #3
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QValidator problem

    I stumbled across QDoubleSpinBox, that fixed it for me.

    Qt Code:
    1. QWidget* StringDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &,const QModelIndex &) const
    2. {
    3. QDoubleSpinBox *dspin = new QDoubleSpinBox(parent);
    4.  
    5. dspin->setRange(0, 5.1);
    6. return dspin;
    7. }
    To copy to clipboard, switch view to plain text mode 

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.