Here is the equivalent extracted code:
#include <QApplication> #include <QWidget> #include <QVBoxLayout> #include <QTextBrowser> #include <QTextEdit> class ChatMessageEdit : public QTextEdit { public: ChatMessageEdit(QWidget* parent) : QTextEdit(parent) { } virtual QSize sizeHint() const { return QSize(0, 25); } }; int main(int argc, char** argv) { QApplication app(argc, argv); QWidget* widget = new QWidget; QVBoxLayout* layout = new QVBoxLayout; QTextBrowser* log = new QTextBrowser(widget); layout->addWidget(log, 1); ChatMessageEdit* editor = new ChatMessageEdit(widget); editor->setMinimumHeight(editor->sizeHint().height()); // empty layout->addWidget(editor); widget->setLayout(layout); widget->show(); return app.exec(); }
The minimum size for the editor is 25 pixels, and the minimum size. But for some strange reason, it is created with a size of about 100 pixels, which is always preferable to tips of my size. Everything else works as expected: extension (size hint is actually not fixed in my application), compression, etc. I tried to change the size policy, but with absolutely no result.
source share