comparison src/gui/widgets/text.cpp @ 50:10868c3fb2be

text.cpp: set paragraph width from document, labelled texts are now... dependent on sizeHint()
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Sep 2023 13:50:56 -0400
parents f4bea5ef5b8a
children 75c804f713b2
comparison
equal deleted inserted replaced
49:f4bea5ef5b8a 50:10868c3fb2be
81 labels = new Paragraph(label, this); 81 labels = new Paragraph(label, this);
82 labels->setTextInteractionFlags(Qt::NoTextInteraction); 82 labels->setTextInteractionFlags(Qt::NoTextInteraction);
83 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); 83 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents);
84 labels->setWordWrapMode(QTextOption::NoWrap); 84 labels->setWordWrapMode(QTextOption::NoWrap);
85 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 85 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
86 labels->setFixedWidth(123);
87 86
88 paragraph = new Paragraph(data, this); 87 paragraph = new Paragraph(data, this);
89 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); 88 paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
90 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); 89 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents);
91 paragraph->setWordWrapMode(QTextOption::NoWrap); 90 paragraph->setWordWrapMode(QTextOption::NoWrap);
92 91
93 QHBoxLayout* content_layout = new QHBoxLayout; 92 QHBoxLayout* content_layout = new QHBoxLayout(content);
94 content_layout->addWidget(labels, 0, Qt::AlignTop); 93 content_layout->addWidget(labels, 0, Qt::AlignTop);
95 content_layout->addWidget(paragraph, 0, Qt::AlignTop); 94 content_layout->addWidget(paragraph, 0, Qt::AlignTop);
96 content_layout->setSpacing(0); 95 content_layout->setSpacing(20);
97 content_layout->setMargin(0); 96 content_layout->setMargin(0);
98 content->setLayout(content_layout);
99 97
100 content->setContentsMargins(12, 0, 0, 0); 98 content->setContentsMargins(12, 0, 0, 0);
101 99
102 layout()->addWidget(header); 100 layout()->addWidget(header);
103 layout()->addWidget(content); 101 layout()->addWidget(content);
167 doc->adjustSize(); 165 doc->adjustSize();
168 long h = 0; 166 long h = 0;
169 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { 167 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) {
170 h += doc->documentLayout()->blockBoundingRect(line).height(); 168 h += doc->documentLayout()->blockBoundingRect(line).height();
171 } 169 }
172 return QSize(QPlainTextEdit::sizeHint().width(), h); 170 return QSize(doc->size().width(), h);
173 } 171 }
174 172
175 QSize Paragraph::sizeHint() const { 173 QSize Paragraph::sizeHint() const {
176 return minimumSizeHint(); 174 return minimumSizeHint();
177 } 175 }