Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Drawing the text as QLineEdit+InputMask does.
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. :)
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
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.
To draw the control you could use two QStyle::drawPrimitive calls. One with
QStyle::PE_PanelLineEditelement to draw the background and
QStyle::PE_FrameLineEditto draw the frame.
You can then use QStyle::subElementRect() with
QStyle::SE_LineEditContentsparam 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::drawTextshould be fine.
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.