Drawing the text as QLineEdit+InputMask does.
-
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. :) -
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 itspaintEvent()
. If you don't go wild with customization you can get away with couple calls toQStyle
andQPainter::drawText
. -
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 itspaintEvent()
. If you don't go wild with customization you can get away with couple calls toQStyle
andQPainter::drawText
.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. -
To draw the control you could use two QStyle::drawPrimitive calls. One with
QStyle::PE_PanelLineEdit
element to draw the background andQStyle::PE_FrameLineEdit
to draw the frame.
You can then use QStyle::subElementRect() withQStyle::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. -
To draw the control you could use two QStyle::drawPrimitive calls. One with
QStyle::PE_PanelLineEdit
element to draw the background andQStyle::PE_FrameLineEdit
to draw the frame.
You can then use QStyle::subElementRect() withQStyle::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.@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 inchSo drawText it is.
Thank you