Results 1 to 20 of 30

Thread: QLineEdit set min max range?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    108
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 2 Times in 1 Post

    Question Re: QLineEdit set min max range?

    Hi,

    sorry i don't have get a notification. That's right, but the user can put wrong values to the QLineEdit.

    What can i do?

    Greetings,

    Whitefurrows

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QLineEdit set min max range?

    Quote Originally Posted by whitefurrows
    That's right, but the user can put wrong values to the QLineEdit.
    The problem is that line edit can loose focus when it contains an intermediate value. IMO you should ask the Trolls whether this is a correct behavior.

  3. The following user says thank you to jacek for this useful post:

    whitefurrows (11th June 2006)

  4. #3
    Join Date
    May 2006
    Posts
    108
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 2 Times in 1 Post

    Question Re: QLineEdit set min max range?

    Hi,

    thank's to you. You know a way how can i set focus to a QLineEdit as long as contains an intermediate value?

    Greetings

    Whitefurrows

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QLineEdit set min max range?

    There are many ways to do that. You could override line edit's focusOutEvent(), use an event filter, or install an event filter even on the application. In all cases, you'll just have to ask the validator for it's state and then set the focus back on the line edit when appropriate.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    whitefurrows (11th June 2006)

  7. #5
    Join Date
    May 2006
    Posts
    108
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 2 Times in 1 Post

    Question Re: QLineEdit set min max range?

    Hi,

    can you help me to do that, please?

    I try that:

    Qt Code:
    1. protected:
    2. QLineEdit focusOutEvent(QFocusEvent* event) const;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QLineEdit MyWidget::focusOutEvent(QFocusEvent* event) const{
    2. const QObject* ob=QObject::sender();
    3. int i =0;
    4. while (ob!=lineEditList[i] && i<lineEditList.size())
    5. i++;
    6.  
    7. if(LineEdit Validator state == intermediate) //How can i do that?
    8. leList[i]->setEditFocus(true);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance,

    Whitefurrows

  8. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QLineEdit set min max range?

    The focus out event could look for example something like this:
    Qt Code:
    1. void MyLineEdit::focusOutEvent(QFocusEvent* event)
    2. {
    3. // check validator state
    4. int pos = 0;
    5. QValidator::State state = validator()->validate(text(), pos);
    6.  
    7. if (state == QValidator::Intermediate)
    8. {
    9. // keep focus if intermediate
    10. setFocus();
    11. }
    12. else
    13. {
    14. // otherwise call base class implementation and let it
    15. // handle focus out actions (so cursor stops blinking etc.)
    16. QLineEdit::focusOutEvent(event);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    If you have difficulties in subclassing QLineEdit, I suggest you to switch back to your favourite C++ book and learn the secrects of inheritance..
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    whitefurrows (11th June 2006)

  10. #7
    Join Date
    May 2006
    Posts
    108
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 2 Times in 1 Post

    Question Re: QLineEdit set min max range?

    Hi,

    the problem is i can't subclassing QLineEdit. I use the designer and the designer use the QLineEdit and not MyLineEdit.

    Sorry my stupid question i'm a beginner and learn. Please help me one more time.

    Greetings,

    Whitefurrows

  11. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QLineEdit set min max range?

    You can use the subclassed line edit widget by promoting it as custom widget in the designer. See the context menu of the line edit.
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:

    whitefurrows (11th June 2006)

  13. #9
    Join Date
    May 2006
    Posts
    108
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 2 Times in 1 Post

    Question Re: QLineEdit set min max range?

    Hi,

    thank you that's work, but i have one more problem MyLineEdit keep focus if intermediate but if i press button "Save" can i save the data(that's wrong) and MyLineEdit keep focus.

    Is that OK? What can i do?

    Greetings,

    Whitefurrows

  14. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QLineEdit set min max range?

    Sorry, what's the problem? You'll have to explain a bit more clearly. "Can I save the data" is quite an abstract concept..
    J-P Nurmi

  15. The following user says thank you to jpn for this useful post:

    whitefurrows (11th June 2006)

  16. #11
    Join Date
    May 2006
    Posts
    108
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    35
    Thanked 2 Times in 1 Post

    Question Re: QLineEdit set min max range?

    Sorry, ok i try it. I have many QLineEdit's on a QWidget and a Button. When the user push the butten, then store the programm the values from the QlineEdit's to the database. The user can store the data always, but that is wrong. I wont the user can save the data only if all QlineEdit's contain right values?

    You know what i mean?

  17. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QLineEdit set min max range?

    You could check the validator states whenever QLineEdit::textChanged() signal is emitted. Or you could emit signals (sending state as a parameter) from the validators whenever they are asked to validate. There are many possibilities... But anyway, you have to somehow keep track of the validator states and enable/disable the button when appropriate.

    Edit: just a side note.. have you looked the possibility of using for example QSqlTableModel + QTableView and a custom delegate to provide suitable editor..?
    Last edited by jpn; 5th June 2006 at 21:22.
    J-P Nurmi

  18. The following user says thank you to jpn for this useful post:

    whitefurrows (11th June 2006)

Similar Threads

  1. Replies: 10
    Last Post: 12th February 2009, 08:23
  2. QLineEdit
    By rick_st3 in forum Newbie
    Replies: 1
    Last Post: 14th June 2008, 10:05
  3. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 16:13
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 02:25
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 13:48

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.