Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Is it possible to insert a "-" in lineEdit after 2 characters entered?
Qt 6.11 is out! See what's new in the release blog

Is it possible to insert a "-" in lineEdit after 2 characters entered?

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 3 Posters 644 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _jao_victor_
    wrote on last edited by
    #1

    I have a lineEdit that receives a date in the format dd-mm-yyyy. Is there a function in PyQt5 that makes it possible to add the "-" in LineEdit after the 2 characters for "Day" are typed or will I have to implement it on my own?

    JonBJ 1 Reply Last reply
    0
    • _ _jao_victor_

      I have a lineEdit that receives a date in the format dd-mm-yyyy. Is there a function in PyQt5 that makes it possible to add the "-" in LineEdit after the 2 characters for "Day" are typed or will I have to implement it on my own?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @_jao_victor_
      There is nothing for a QLineEdit, that just accepts text. You would have to subclass and implement your own logic to do this.

      However, since this is for a date you should see QDateEdit Class which does effectively do this, and is a better choice than QLineEdit. It also returns the date as a date, so you don't have to parse. And you may be further interested in using its Using a Pop-up Calendar Widget optional feature.

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Depending on what you need, QLineEdit::setInputMask might be enough for your purpose.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved