Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using a Mask in QLineEdit Changes Cursor Thickness and Position
QtWS25 Last Chance

Using a Mask in QLineEdit Changes Cursor Thickness and Position

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k Views
  • 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.
  • R Offline
    R Offline
    RRRitchey
    wrote on last edited by
    #1

    I have a line edit that I specified with right alignment. When I do not have a mask set the cursor starts on the right side of the edit box and is normal. When I set a Mask, the cursor now starts in the middle of the box and is thicker than normal. I don't know why this is happening. I will admit I am just learning Qt but reading through the QLineEdit description I see nothing that indicates this change will happen. How do I get this to act the same way with a Mask as it does without a Mask.

    @
    lineEditUnitProdCode = new QLineEdit;
    lineEditUnitProdCode->setMaxLength(3);
    lineEditUnitProdCode->setInputMask("000");
    lineEditUnitProdCode->setFixedWidth(CharAveWidth*5);
    lineEditUnitProdCode->setPlaceholderText(tr("000"));
    lineEditUnitProdCode->setAlignment(Qt::AlignRight);
    @

    Thank you,

    [edit: added missing coding tags @ SGaist]

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

      Hi and welcome to devnet,

      AFAIK, the thicker cursor is a visual cue that allows the user to know that it's not a generic line edit and not get angry because he can't see everything he's typing in.

      The wrong cursor position comes from the fact that it's on the last masked position but since there are no char it looks like it's in the middle of the placeholder text. However that could be a bug. You should have a look at the "bug report system":http://bugreports.qt-project.org to see if it's something known. If not please consider opening a new report providing a minimal compilable example that allows to reproduce the problem.

      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
      0
      • R Offline
        R Offline
        RRRitchey
        wrote on last edited by
        #3

        Hi, thank you. Learn something new every day. I will check the bug report system about the cursor position. It seems easy to reproduce. After all this I found out about spin boxes and they will work better in this situation. Years of embedded programming in C but all new to C++, Qt and GUIs in general. Thanks again.

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

          Indeed, if you only need numerical values a QSpinBox is much better, you can even hide the buttons if needed

          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
          0

          • Login

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