Perhaps you could simply use QTextEdit?
{
Q_OBJECT
public:
TextEdit
(const QString
& text,
QWidget* parent
= 0) {
// make it look and feel like an ordinary label
setReadOnly(true);
setFrameStyle
(QFrame::NoFrame);
pal.
setColor(QPalette::Base, Qt
::transparent);
setPalette(pal);
// wrap anywhere, adjust minimum height on the fly
connect(document()->documentLayout(),
SIGNAL(documentSizeChanged
(QSizeF)),
this,
SLOT(adjustMinimumSize
(QSizeF)));
}
private slots:
void adjustMinimumSize(const QSizeF& size)
{
setMinimumHeight(size.height() + 2 * frameWidth());
}
};
class TextEdit : public QTextEdit
{
Q_OBJECT
public:
TextEdit(const QString& text, QWidget* parent = 0)
: QTextEdit(text, parent)
{
// make it look and feel like an ordinary label
setReadOnly(true);
setFrameStyle(QFrame::NoFrame);
QPalette pal = palette();
pal.setColor(QPalette::Base, Qt::transparent);
setPalette(pal);
// wrap anywhere, adjust minimum height on the fly
setLineWrapMode(QTextEdit::WidgetWidth);
setWordWrapMode(QTextOption::WrapAnywhere);
connect(document()->documentLayout(),
SIGNAL(documentSizeChanged(QSizeF)),
this, SLOT(adjustMinimumSize(QSizeF)));
}
private slots:
void adjustMinimumSize(const QSizeF& size)
{
setMinimumHeight(size.height() + 2 * frameWidth());
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks