Results 1 to 17 of 17

Thread: problem withh returnPressed

  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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    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 

  10. #10
    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

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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"?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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 

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

    Default Re: problem withh returnPressed

    Quote Originally Posted by wysota
    Here is my code, try it:
    hi I have change ur code according to my situation because i dont use QLineEdit as a class i have qtable and just one COL is made QlineEdit, this is the code:

    Qt Code:
    1. QWidget* TestTableItem::createEditor() const
    2. {
    3.  
    4. QLineEdit* le = ( QLineEdit *)(QTableItem::createEditor());
    5. QString input;
    6. int v = input.toInt();
    7.  
    8. if (le)
    9. {
    10. QIntValidator* validator = new QIntValidator( 3,16000 , le );
    11. if(v > validator->bottom()) input = QString::number(validator->bottom());
    12. if(v <validator->top()) input = QString::number(validator->top());
    13. validator->fixup(input);
    14. le->setValidator(validator);
    15.  
    16. }
    17.  
    18. return le;
    19. }
    To copy to clipboard, switch view to plain text mode 

    the fixup doesnt work good because i am still able to write 1 and 2
    Love::Peace

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

    Default Re: problem withh returnPressed

    Maybe you didn't notice -- I subclassed QIntValidator. The default implementation of fixup() does nothing so you have to subclass the validator and implement it.

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

    Default Re: problem withh returnPressed

    Quote Originally Posted by wysota
    Maybe you didn't notice -- I subclassed QIntValidator. The default implementation of fixup() does nothing so you have to subclass the validator and implement it.
    oke i see i have also subclass QIntvalidator:
    Qt Code:
    1. class MyIntValidator : public QIntValidator {
    2.  
    3. public:
    4.  
    5. MyIntValidator(int l, int t, QObject *p=0) : QIntValidator(l,t,p){}
    6.  
    7. void fixup(QString &input) const;
    8.  
    9. };
    10.  
    11. void MyIntValidator::fixup(QString &input) const {
    12.  
    13. int v = input.toInt();
    14.  
    15. if(v<bottom()) input = QString::number(bottom());
    16.  
    17. if(v>top()) input = QString::number(top());
    18.  
    19. }
    20.  
    21. QWidget* TestTableItem::createEditor() const
    22. {
    23.  
    24. QLineEdit* le = ( QLineEdit *)(QTableItem::createEditor());
    25.  
    26. QIntValidator* validator = new QIntValidator(3,16000 , le );
    27. le->setValidator(validator);
    28.  
    29. return le;
    30. }
    To copy to clipboard, switch view to plain text mode 

    but still its not working, am i doing somthing wrong with subclassing??
    Love::Peace

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

    Default Re: problem withh returnPressed

    Qt Code:
    1. QIntValidator* validator = new QIntValidator(3,16000 , le );
    To copy to clipboard, switch view to plain text mode 
    You are still creating an instance of QIntValidator instead of your subclass.

  17. The following user says thank you to wysota for this useful post:

    :db:sStrong (23rd May 2006)

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

    Default Re: problem withh returnPressed

    Quote Originally Posted by wysota
    Qt Code:
    1. QIntValidator* validator = new QIntValidator(3,16000 , le );
    To copy to clipboard, switch view to plain text mode 
    You are still creating an instance of QIntValidator instead of your subclass.


    oh jeeeeeee lol i see it now, i should do this:

    Qt Code:
    1. MyIntValidator * validator = new MyIntValidator(3,16000,le);
    To copy to clipboard, switch view to plain text mode 

    oke thanx alot for ur help
    Love::Peace

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