diff 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
line wrap: on
line diff
--- a/src/gui/widgets/text.cpp	Mon Sep 25 01:07:22 2023 -0400
+++ b/src/gui/widgets/text.cpp	Mon Sep 25 11:40:14 2023 -0400
@@ -5,6 +5,7 @@
 #include <QPixmap>
 #include <QTextBlock>
 #include <QVBoxLayout>
+#include <QDebug>
 
 namespace TextWidgets {
 
@@ -163,8 +164,11 @@
 /* highly based upon... some stackoverflow answer for PyQt */
 QSize Paragraph::minimumSizeHint() const {
 	QTextDocument* doc = document();
-	long h = (long)(blockBoundingGeometry(doc->findBlockByNumber(doc->blockCount() - 1)).bottom() +
-	                (2 * doc->documentMargin()));
+	doc->adjustSize();
+	long h = 0;
+	for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) {
+		h += doc->documentLayout()->blockBoundingRect(line).height();
+	}
 	return QSize(QPlainTextEdit::sizeHint().width(), h);
 }