PDA

View Full Version : Painting to QTextEdit



gesslar
17th February 2006, 03:11
I have a problem painting to a QTextEdit.

This works:



QTabWidget *tabs;
tabs->currentWidget() = a subclassed QTextEdit

void EditorWin::paintEvent ( QPaintEvent *e ) {
QPainter p(this);
p.drawLine(0,0,width(), height());
}


However, as expected, it draws the line from the top-left to the bottom-right, BEHIND the QTabWidget.

So, I tried to paint where I wanted the line to show up:



QTabWidget *tabs;
tabs->currentWidget() = a subclassed QTextEdit

void EditorWin::paintEvent ( QPaintEvent *e ) {
QPainter p(tabs->currentWidget());
p.drawLine(0,0,width(), height());
}


This will NOT draw, and I have no idea why. Could anybody help?

Win32/Qt4.1

Edit: I also tried to run this through the paintEvent of the subclassed QTextEdit widget, same result: no drawing :(

zlatko
17th February 2006, 11:14
have you show it before painting?

high_flyer
17th February 2006, 17:16
So, I tried to paint where I wanted the line to show up:


QTabWidget *tabs;
tabs->currentWidget() = a subclassed QTextEdit

void EditorWin::paintEvent ( QPaintEvent *e ) {
QPainter p(tabs->currentWidget());
p.drawLine(0,0,width(), height());
}



This code draws WHERE you want, but not WHEN you want it.
It draws on the correct widget, but during the time you show the EditorWin widget.
You have to put the drawing code in the paintEvent of the widget you are dorwing on.

gesslar
18th February 2006, 01:02
have you show it before painting?

Definately visible.

gesslar
18th February 2006, 01:03
This code draws WHERE you want, but not WHEN you want it.
It draws on the correct widget, but during the time you show the EditorWin widget.
You have to put the drawing code in the paintEvent of the widget you are dorwing on.

I'm not sure if you saw the text at the bottom of my post, but

Edit: I also tried to run this through the paintEvent of the subclassed QTextEdit widget, same result: no drawing

gesslar
18th February 2006, 03:55
One further piece of information though I'm unsure if it matters, my QTextEdits are in a QTabWidget.

gesslar
18th February 2006, 09:57
void MPadDoc::paintEvent ( QPaintEvent *e ) {
QPainter p(this);
p.drawLine(0,0,width(), height());
e->ignore();

}

(Where MPadDoc is a subclass of QTextEdit)

I compiled it under linux and when I tried to run the above code, I get
the following in my Konsole: QPainter::begin: Widget painting can only
begin as a result of a paintEvent

So, even though I *am* doing this in a paintEvent, it's complaining
about it. :(.

I totally wish someone would know what I can do.

It's also worth mentioning that while I am a "reimplimenting paintEvent", it complains with the same error message when I type in the textedit.

michel
18th February 2006, 14:13
void MPadDoc::paintEvent ( QPaintEvent *e ) {
QPainter p(this);
p.drawLine(0,0,width(), height());
e->ignore();

}

Try taking the e->ignore() out and just making it say



{
QPainter p(this);
p.drawLine(0, 0, width(), height());
}


I think this error you get is coming from the fact you are telling the parent to take care of the painting event for a widget which is covering part of it.

gesslar
18th February 2006, 19:40
http://doc.trolltech.com/4.1/qabstractscrollarea.html#paintEvent

That is what solved my problem. See attached my final results!