Hello,
I'm trying to draw on a QTextEdit. I've been able to do so by subclassing QTextEdit and reimplementing the paintEvent function. However, when I scroll the QTextEdit, the line I drew doesn't scroll with it (which I need it to do). It doesn't just stay either, it gets messed up into a whole bunch of lines. Eventually I also want to be able to print the QTextEdit (with the lines).
So I can see two ways of approaching it (maybe I'm wrong) but don't know how to do either.
1) Draw on the QTextEdit widget. I would need to figure out how to make the lines scroll and also how to reimplement the print functions myself, since the print functions for QTextEdit operate on the QTextDocument class underlying the QTextEdit.
2) Draw on a QPixmap and then inserting that into the QTextEdit/QTextDocument. Can images be inserted over the whole text area as foreground (preferably, but background could be ok) to the TextEdit?
Any pointers would be appreciated. Thanks.
{
pe.setColor(Qt::red);
pe.setWidth(2);
painter.setPen(pe);
painter.
setRenderHint(QPainter::Antialiasing,
true);
painter.drawLine(0,0,viewport()->maximumWidth()-1,viewport()->maximumHeight()-1);
}
void JTextEdit::paintEvent(QPaintEvent *event)
{
QTextEdit::paintEvent(event);
QPainter painter(viewport());
QPen pe;
pe.setColor(Qt::red);
pe.setWidth(2);
painter.setPen(pe);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawLine(0,0,viewport()->maximumWidth()-1,viewport()->maximumHeight()-1);
}
To copy to clipboard, switch view to plain text mode
Bookmarks