Results 1 to 6 of 6

Thread: setInputMask prevent the use of spaces and avoid the sense that something's written

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question setInputMask prevent the use of spaces and avoid the sense that something's written

    Hello.
    I have a lineedit and I have set its input mask to nnnnnn (numbers+letters) but I have two major problems:
    1) I don't want when I click to the lineedit the cursor to go to the end(it goes to the X position where X is the number of the 'nnnn' I have set to the input mask), as there is something written to the lineedit, while it isn't.
    2) I want also to prevent the user from inputting spaces, is this possible?
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setInputMask prevent the use of spaces and avoid the sense that something's writt

    1) I don't want when I click to the lineedit the cursor to go to the end(it goes to the X position where X is the number of the 'nnnn' I have set to the input mask), as there is something written to the lineedit, while it isn't.
    use :

    Qt Code:
    1. ui->lineEdit->setCursorPosition(x);
    To copy to clipboard, switch view to plain text mode 
    where x is the position where you want the cursor to be.

    2) I want also to prevent the user from inputting spaces,
    use the validator :
    Qt Code:
    1. QRegExpValidator *noSpaceValidator=new QRegExpValidator(QRegExp("^[A-Za-z0-9]+"),ui->lineEdit);
    2.  
    3. ui->lineEdit->setValidator(noSpaceValidator);
    To copy to clipboard, switch view to plain text mode 
    Last edited by tinysoft; 22nd May 2011 at 17:00.

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

    hakermania (23rd May 2011)

  4. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setInputMask prevent the use of spaces and avoid the sense that something's writt

    I'd like to use this but the is not a slot that says on_lineedit_focused/clicked
    ui->lineEdit->setCursorPosition(x);
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: setInputMask prevent the use of spaces and avoid the sense that something's writt

    Take a look at QWidget::focusInEvent() and related event handlers.

  6. #5
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setInputMask prevent the use of spaces and avoid the sense that something's writt

    Quote Originally Posted by hakermania View Post
    I'd like to use this but the is not a slot that says on_lineedit_focused/clicked
    ui->lineEdit->setCursorPosition(x);
    this should do the trick :
    Qt Code:
    1. connect(ui->lineEdit,SIGNAL(editingFinished()),this ,SLOT(editFinshied()));
    2.  
    3.  
    4. void MainWindow::setCursor()
    5. {
    6. ui->lineEdit->setCursorPosition(3);
    7. disconnect(ui->lineEdit,SIGNAL(selectionChanged()),this ,SLOT(setCursor()));
    8.  
    9. }
    10.  
    11. void MainWindow::editFinshied()
    12. {
    13. ui->lineEdit->selectAll();
    14. connect(ui->lineEdit,SIGNAL(selectionChanged()),this ,SLOT(setCursor()));
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    good luck !

  7. #6
    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: setInputMask prevent the use of spaces and avoid the sense that something's writt

    Quote Originally Posted by hakermania View Post
    Hello.
    I have a lineedit and I have set its input mask to nnnnnn (numbers+letters) but I have two major problems:
    1) I don't want when I click to the lineedit the cursor to go to the end(it goes to the X position where X is the number of the 'nnnn' I have set to the input mask), as there is something written to the lineedit, while it isn't.
    2) I want also to prevent the user from inputting spaces, is this possible?
    Use a validator instead of an input mask.
    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. QLineEdit and setInputMask
    By mr_kazoodle in forum Newbie
    Replies: 3
    Last Post: 23rd January 2011, 15:47
  2. Replies: 7
    Last Post: 13th November 2010, 07:58
  3. designer intelli-sense
    By mhoover in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2010, 13:25
  4. PHP extensions written in C++/Qt
    By seim in forum Qt Programming
    Replies: 0
    Last Post: 12th February 2009, 00:40
  5. qsqldatabase does not sense db disconnect
    By rburge in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2006, 18:59

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.