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. Drawing the text as QLineEdit+InputMask does.

Drawing the text as QLineEdit+InputMask does.

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 652 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #1

    Hi
    I have a delegate that
    creates a LineEdit and sets an inputmask on it.

    This is purely for presentation and this format is not saved to the model.

    However, im looking for some drawText
    function to draw it like the LineEdit does so it can look the same
    in/out of editing the item.

    Even its easy to mimic manually, i was wondering if there was some function for it that i
    keep not seeing looking around in the source. :)

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      AFAIK there's no single method that does it. At least Qt itself doesn't seem to be using anything like that internally.
      I'd just mimic what QLineEdit does internally in its paintEvent(). If you don't go wild with customization you can get away with couple calls to QStyle and QPainter::drawText.

      mrjjM 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        AFAIK there's no single method that does it. At least Qt itself doesn't seem to be using anything like that internally.
        I'd just mimic what QLineEdit does internally in its paintEvent(). If you don't go wild with customization you can get away with couple calls to QStyle and QPainter::drawText.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @chris-kawa

        Hi
        ok so seems there is no dedicated function as such.
        thx for confirming. :)

        Can you elaborate on what QStyle calls you are thinking of?
        Only using QPainter currently so im curious.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          To draw the control you could use two QStyle::drawPrimitive calls. One with QStyle::PE_PanelLineEdit element to draw the background and QStyle::PE_FrameLineEdit to draw the frame.
          You can then use QStyle::subElementRect() with QStyle::SE_LineEditContents param to get the exact rectangle for the text.

          QLineEdit uses QTextLayout internally to draw the text, but if you don't do any formatting, alignment or other shenanigans simple QPainter::drawText should be fine.

          mrjjM 1 Reply Last reply
          2
          • Chris KawaC Chris Kawa

            To draw the control you could use two QStyle::drawPrimitive calls. One with QStyle::PE_PanelLineEdit element to draw the background and QStyle::PE_FrameLineEdit to draw the frame.
            You can then use QStyle::subElementRect() with QStyle::SE_LineEditContents param to get the exact rectangle for the text.

            QLineEdit uses QTextLayout internally to draw the text, but if you don't do any formatting, alignment or other shenanigans simple QPainter::drawText should be fine.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @chris-kawa
            Ah, for the exact look.
            I can see how my question sounds like that in retro reading.
            It was only the text part. not rest of the LineWidget but
            QStyle::subElementRect() is a good idea as i have a slight pixel shift and
            it makes it look better when open/close editor.

            Well no, shenanigans :)
            Its just Feet|Inch|1/16 inch

            So drawText it is.

            Thank you

            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