Mercurial > minori
comparison src/gui/widgets/text.cpp @ 49:f4bea5ef5b8a
paragraph: fix size hint
only tested on Linux (KDE)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Mon, 25 Sep 2023 11:40:14 -0400 |
| parents | d0adc4aedfc8 |
| children | 10868c3fb2be |
comparison
equal
deleted
inserted
replaced
| 48:e613772f41d5 | 49:f4bea5ef5b8a |
|---|---|
| 3 #include <QFrame> | 3 #include <QFrame> |
| 4 #include <QLabel> | 4 #include <QLabel> |
| 5 #include <QPixmap> | 5 #include <QPixmap> |
| 6 #include <QTextBlock> | 6 #include <QTextBlock> |
| 7 #include <QVBoxLayout> | 7 #include <QVBoxLayout> |
| 8 #include <QDebug> | |
| 8 | 9 |
| 9 namespace TextWidgets { | 10 namespace TextWidgets { |
| 10 | 11 |
| 11 Header::Header(QString title, QWidget* parent) : QWidget(parent) { | 12 Header::Header(QString title, QWidget* parent) : QWidget(parent) { |
| 12 setLayout(new QVBoxLayout); | 13 setLayout(new QVBoxLayout); |
| 161 } | 162 } |
| 162 | 163 |
| 163 /* highly based upon... some stackoverflow answer for PyQt */ | 164 /* highly based upon... some stackoverflow answer for PyQt */ |
| 164 QSize Paragraph::minimumSizeHint() const { | 165 QSize Paragraph::minimumSizeHint() const { |
| 165 QTextDocument* doc = document(); | 166 QTextDocument* doc = document(); |
| 166 long h = (long)(blockBoundingGeometry(doc->findBlockByNumber(doc->blockCount() - 1)).bottom() + | 167 doc->adjustSize(); |
| 167 (2 * doc->documentMargin())); | 168 long h = 0; |
| 169 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { | |
| 170 h += doc->documentLayout()->blockBoundingRect(line).height(); | |
| 171 } | |
| 168 return QSize(QPlainTextEdit::sizeHint().width(), h); | 172 return QSize(QPlainTextEdit::sizeHint().width(), h); |
| 169 } | 173 } |
| 170 | 174 |
| 171 QSize Paragraph::sizeHint() const { | 175 QSize Paragraph::sizeHint() const { |
| 172 return minimumSizeHint(); | 176 return minimumSizeHint(); |
