Lykurg
10th March 2010, 13:50
Hi,
I have following class (simplified...):
class MyLabel : public QLabel
{
Q_OBJECT
public:
explicit MyLabel(QWidget *parent = 0, Qt::WindowFlags f = 0);
protected:
void paintEvent(QPaintEvent *event);
private:
QPlainTextEdit *m_doc; //it is hidden, only for storing reason.
};
So assume there is some content in the text edit and I do this:
void MyLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(this);
m_doc->document()->setPageSize(rect().size());
m_doc->document()->drawContents(&p, rect());
}
nothing is shown, but when I have this:
void MyLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(this);
QTextDocument *d = m_doc->document()->clone();
d->setPageSize(rect().size());
d->drawContents(&p, rect());
d->deleteLater();
}
everything is painted well. But why I have to clone the document??? That's not very performant... What might be the reason why I am not able to use QPlainTextEdit::document() directly?
Thanks
I have following class (simplified...):
class MyLabel : public QLabel
{
Q_OBJECT
public:
explicit MyLabel(QWidget *parent = 0, Qt::WindowFlags f = 0);
protected:
void paintEvent(QPaintEvent *event);
private:
QPlainTextEdit *m_doc; //it is hidden, only for storing reason.
};
So assume there is some content in the text edit and I do this:
void MyLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(this);
m_doc->document()->setPageSize(rect().size());
m_doc->document()->drawContents(&p, rect());
}
nothing is shown, but when I have this:
void MyLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(this);
QTextDocument *d = m_doc->document()->clone();
d->setPageSize(rect().size());
d->drawContents(&p, rect());
d->deleteLater();
}
everything is painted well. But why I have to clone the document??? That's not very performant... What might be the reason why I am not able to use QPlainTextEdit::document() directly?
Thanks