Hi,
I have following class (simplified...):
{
Q_OBJECT
public:
explicit MyLabel
(QWidget *parent
= 0, Qt
::WindowFlags f
= 0);
protected:
private:
QPlainTextEdit *m_doc; //it is hidden, only for storing reason.
};
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.
};
To copy to clipboard, switch view to plain text mode
So assume there is some content in the text edit and I do this:
{
Q_UNUSED(event);
m_doc->document()->setPageSize(rect().size());
m_doc->document()->drawContents(&p, rect());
}
void MyLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(this);
m_doc->document()->setPageSize(rect().size());
m_doc->document()->drawContents(&p, rect());
}
To copy to clipboard, switch view to plain text mode
nothing is shown, but when I have this:
{
Q_UNUSED(event);
d->setPageSize(rect().size());
d->drawContents(&p, rect());
d->deleteLater();
}
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();
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks