Results 1 to 6 of 6

Thread: Change only part of QLineEdit with input mask - possible?

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Change only part of QLineEdit with input mask - possible?

    Hello!

    I have a line edit with an input mask with, say, 5 characters.

    Question is this: can I somehow make QLineEdit to allow to change only last 3 chars in accordance to mask, and leave the first 2 untouched - as they were set by initial setText()?

    To rephrase: I need an input mask to be set on part of the text, while not allowing to change another part.

    I guess this is impossible, but who knows, Qt has many tricks

    TIA.

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change only part of QLineEdit with input mask - possible?

    Use escaped characters in the inputMask to display unchangable text. This, for example displays "TestXXX", where you can only edit the "XXX" part.

    Qt Code:
    1. lineEdit->setInputMask("\\T\\e\\s\\tAAA");
    2. lineEdit->setText("TestXXX");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change only part of QLineEdit with input mask - possible?

    Wow, isn't that cool
    Thank you!

  4. #4
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change only part of QLineEdit with input mask - possible?

    Heh, now I have another question:

    I need to paint part of the line edit's text in one color and other part in another color.
    The only way I see is reimplementing paintEvent with all the drawing - frame, margins, text.

    But maybe there's some quicker way?

  5. #5
    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: Change only part of QLineEdit with input mask - possible?

    No, QLineEdit doesn't allow you to use rich text.
    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.


  6. #6
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change only part of QLineEdit with input mask - possible?

    Ok, just figured out that this particular feature is not strictly needed, so it can be dropped

Similar Threads

  1. QLineEdit and input mask
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 9th May 2014, 19:47
  2. how to make input mask and validator work together?
    By homerli in forum Qt Programming
    Replies: 11
    Last Post: 5th June 2009, 09:53
  3. input mask problem
    By zgulser in forum Qt Programming
    Replies: 10
    Last Post: 8th May 2009, 14:11
  4. Mixing QRegExpValidator and input mask and QLineEdit
    By abernat in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2009, 00:04
  5. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13

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.