QFontMetrics m (font()) ;int RowHeight =m.lineSpacing()
C++ (Qt)QFontMetrics::height
C++ (Qt)int QFontMetrics::height () constReturns the height of the font.This is always equal to ascent()+descent()+1 (the 1 is for the base line).See also leading() and lineSpacing().
C++ (Qt)int QFontMetrics::lineSpacing () constReturns the distance from one base line to the next.This value is always equal to leading()+height().See also height() and leading().
C++ (Qt)int QFontMetrics::leading () constReturns the leading of the font.This is the natural inter-line spacing.See also height() and lineSpacing().
C++ (Qt) int height = QFontMetrics(font()).boundingRect(QRect(), alignment, text).height();
C++ (Qt)#include <QApplication>#include <QWidget>#include <QVBoxLayout>#include <QTextBrowser> int main(int argc, char **argv){ QApplication app(argc, argv); QWidget *pWidget = new QWidget; QTextBrowser *pText = new QTextBrowser; pText->setSource(QUrl("qrc:/all/files/index.html")); pText->adjustSize(); QVBoxLayout *pLayoutVertical = new QVBoxLayout; pLayoutVertical->addStretch(1); pLayoutVertical->addWidget(pText, 0); pWidget->setLayout(pLayoutVertical); pWidget->showMaximized(); return app.exec();}
C++ (Qt)QSize MyTextEdit::sizeHint() const{ QMargins m(contentsMargins()); return document()->size() + QSize(m.left() + m.right(), m.top() + m.bottom());}
C++ (Qt)#include <QApplication>#include <QWidget>#include <QVBoxLayout>#include <QTextBrowser>#include <iostream> class evgTextBrowser : public QTextBrowser{public: explicit evgTextBrowser(QWidget *parent = 0) : QTextBrowser(parent) {} QSize sizeHint() const { QMargins m(contentsMargins()); return document()->size().toSize() + QSize(m.left() + m.right(), m.top() + m.bottom()); }}; int main(int argc, char **argv){ QApplication app(argc, argv); QWidget *pWidget = new QWidget; evgTextBrowser *pText = new evgTextBrowser; pText->setSource(QUrl("qrc:/all/files/index.html")); pText->adjustSize(); QVBoxLayout *pLayoutVertical = new QVBoxLayout; pLayoutVertical->addStretch(1); pLayoutVertical->addWidget(pText, 0); pWidget->setLayout(pLayoutVertical); pWidget->showMaximized(); return app.exec();}
C++ (Qt)return document()->size() + QSize(m.left() + m.right(), m.top() + m.bottom());
C++ (Qt)#ifndef EVGTEXTBROWSER_H#define EVGTEXTBROWSER_H #include <QTextBrowser> class evgTextBrowser : public QTextBrowser{ Q_OBJECTpublic: explicit evgTextBrowser(QWidget *parent = 0); QSize sizeHint() const; QSize minimumSizeHint() const; signals: public slots: }; #endif // EVGTEXTBROWSER_H
C++ (Qt)#include "evgtextbrowser.h" evgTextBrowser::evgTextBrowser(QWidget *parent) : QTextBrowser(parent){} QSize evgTextBrowser::sizeHint() const{ if (document()->isEmpty()) return QSize(0, 0); else { QMargins m(contentsMargins()); return document()->size().toSize() + QSize(m.left() + m.right(), m.top() + m.bottom()); }} QSize evgTextBrowser::minimumSizeHint() const{ if (document()->isEmpty()) return QSize(0, 0); else return document()->size().toSize();}