PDA

View Full Version : Draw vertical Line in QTextEdit



ericV
22nd July 2009, 16:00
Hi there,

I am in the process of writing a custom Code /Script Editor. An i thought i would be nice to have a "vertical - line" drwan along the right side of the "Text" as a page delimiter.

I have tried to find something on this but i guess im not using the right Keywords. :confused:

I found something while goting through the list of possible things provided by the syntaxcompleter:

QTextEdit::VLine
QTextEdit::HLine

But i have no clue waht i can do with these... (and even if they are what im thinking about) I havent been able to find them in the documentation... so I ask here :o

If anyone can give me a tip on how to acomplish this, id be grateful.

wysota
22nd July 2009, 16:04
I don't think you'd want to use these... You probably have to draw a regular line using QPainter in appropriate place of the viewport.

ericV
22nd July 2009, 16:29
Thanks for the sudgestion.... i will try it with the QPainter

Edit:
Cant seem to get it to work.... it compiles but there is no line ...
i wrote this in my constructor for the editor:



QPainter linePainter(editor);

int y1 = editor->rect().topLeft().y();
int y2 = editor->rect().bottomLeft().y();
int x = editor->rect().topLeft().x();
x += QFontMetrics(f).width("x")*70;

QLine vLine = QLine(x,y1,x,y2) ;

linePainter.drawLine(vLine);

wysota
22nd July 2009, 16:50
It doesn't work like that. You have to paint the line from within the paint event each time your widget is redrawn.