Results 1 to 17 of 17

Thread: problem withh returnPressed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default problem withh returnPressed

    Hi volks,
    I have a qtable en qtableItems class but i have made one col as QlineEdit. This is the code

    Qt Code:
    1. QWidget* testTableItem::createEditor() const
    2. {
    3.  
    4. QLineEdit* le = ( QLineEdit *)(QTableItem::createEditor());
    To copy to clipboard, switch view to plain text mode 
    .......
    ......
    }

    I have reimplemented createEditor and in here i have made a validator for the qlineEdit.

    Now i have a problem with the validator, i dont want to write 1, 2 inside the qline but i should be able to write 11 and 12 and in order to implement this i want to use events like pressReturned signal of qlineedit. I dont have qlineedit and is it possible to use pressRetuned signal in above situation?

    thanx in advance
    Love::Peace

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

    Default Re: problem withh returnPressed

    Why can't you use regular Qt validating mechanisms (meaning a subclass of QValidator)?

  3. #3
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh returnPressed

    Quote Originally Posted by wysota
    Why can't you use regular Qt validating mechanisms (meaning a subclass of QValidator)?
    i use regular expression but it is not doing what i want. I want to type the integers bigger than 2 and smaller than 16000, if i am not able to write 1 and 2 how can i type 11 and 12?

    thats why i want to use pressReturned in order to ignore 1 and 2 if type but do accept 11 and 12 and onwards..
    Love::Peace

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

    Default Re: problem withh returnPressed

    Quote Originally Posted by :db:sStrong
    i use regular expression but it is not doing what i want. I want to type the integers bigger than 2 and smaller than 16000, if i am not able to write 1 and 2 how can i type 11 and 12?
    How about using QIntValidator?

    Besides, you can do it with regular expressions as well, something like this should work:

    Qt Code:
    1. QRegExp("([3-9][0-9]{0,3})|(2[0-9]{1,3})|(1(([0-6][0-9]{0,3})|([7-9][0-9]{0-2})))");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh returnPressed

    Quote Originally Posted by wysota
    How about using QIntValidator?

    Besides, you can do it with regular expressions as well, something like this should work:

    Qt Code:
    1. QRegExp("([3-9][0-9]{0,3})|(2[0-9]{1,3})|(1(([0-6][0-9]{0,3})|([7-9][0-9]{0-2})))");
    To copy to clipboard, switch view to plain text mode 

    this reg doesnt work i am not able to type anything
    Love::Peace

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 80 Times in 74 Posts

    Default Re: problem withh returnPressed

    Why dont you use QIntValidator (as suggested by wysota) and set the range ?

  7. #7
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh returnPressed

    Quote Originally Posted by munna
    Why dont you use QIntValidator (as suggested by wysota) and set the range ?
    i am using now QIntValidator:

    Qt Code:
    1. QIntValidator* validator = new QIntValidator( 3,16000 , le );
    2. validator->setRange(3,16000);
    3. le->setValidator(validator);
    4. le->clear();
    To copy to clipboard, switch view to plain text mode 

    but i am still able to type 1 and 2 i want to have this: >2 and <=16000. the top is good but the bottom value is not good in above code.
    Love::Peace

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

    Default Re: problem withh returnPressed

    Quote Originally Posted by :db:sStrong
    i am using now QIntValidator:

    Qt Code:
    1. QIntValidator* validator = new QIntValidator( 3,16000 , le );
    2. validator->setRange(3,16000);
    3. le->setValidator(validator);
    4. le->clear();
    To copy to clipboard, switch view to plain text mode 

    but i am still able to type 1 and 2 i want to have this: >2 and <=16000. the top is good but the bottom value is not good in above code.
    You can type "1" because to type "1000" you have to be able to type "1" It's just not being accepted as a valid value, but you have to be able to type it in. I think that if the lineedit loses focus, the value will be corrected to a valid one. But maybe it'd be easier for you to use QSpinBox?

  9. #9
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh returnPressed

    Quote Originally Posted by wysota
    You can type "1" because to type "1000" you have to be able to type "1" It's just not being accepted as a valid value, but you have to be able to type it in. I think that if the lineedit loses focus, the value will be corrected to a valid one. But maybe it'd be easier for you to use QSpinBox?
    no i have to use qlineedit in order to clear. the users should only type >2 and <16000 i am going to use focus now lets see what happens..
    Love::Peace

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

    Default Re: problem withh returnPressed

    So tell me something. How do you intend to enter "1111" (which is a valid value) if you forbid to enter a "1"?

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

    Default Re: problem withh returnPressed

    Here is my code, try it:

    Qt Code:
    1. #include <QApplication>
    2. #include <QIntValidator>
    3. #include <QLineEdit>
    4. #include <QDialog>
    5. #include <QVBoxLayout>
    6.  
    7. class MyIntValidator : public QIntValidator {
    8. public:
    9. MyIntValidator(int l, int t, QObject *p=0) : QIntValidator(l,t,p){}
    10. void fixup(QString &input) const;
    11. };
    12.  
    13. void MyIntValidator::fixup(QString &input) const {
    14. int v = input.toInt();
    15. if(v<bottom()) input = QString::number(bottom());
    16. if(v>top()) input = QString::number(top());
    17. }
    18.  
    19. int main(int argc, char **argv){
    20. QApplication app(argc, argv);
    21. QDialog dlg;
    22. QVBoxLayout *layout = new QVBoxLayout;
    23. QLineEdit *le = new QLineEdit(&dlg);
    24. QLineEdit *other = new QLineEdit(&dlg);
    25. layout->addWidget(le);
    26. layout->addWidget(other);
    27. dlg.setLayout(layout);
    28. QIntValidator *validator = new MyIntValidator(3,16000, le);
    29. le->setValidator(validator);
    30. dlg.show();
    31. return app.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Posts
    667
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 80 Times in 74 Posts

    Default Re: problem withh returnPressed

    I think you need to use QSpinBox.

    If you are very particular about QLineEdit then try

    Qt Code:
    1. QWidget *testTableItem::createEditor() const
    2. {
    3. QLineEdit *lineEdit = new QLineEdit(viewport());
    4. lineEdit->setFrame(false);
    5. //use connect here.
    6. return lineEdit;
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. problem withh QListViewItemIterator
    By :db:sStrong in forum Qt Programming
    Replies: 10
    Last Post: 7th March 2007, 14:05
  4. Replies: 16
    Last Post: 7th March 2006, 15:57

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.