Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2653

Setting the font of a QTextEdit has no effect after changing QTextDocument objects

    XMLWordPrintable

Details

    Description

      In the following example the text is 12 points large only in the first report generated, all later reports have small fonts. Using setDefaultFont instead works correctly.

      #include <QtGui>

      class MainWindow: public QMainWindow
      {
      Q_OBJECT
      public:
      MainWindow(QWidget * parent = 0)
      : QMainWindow(parent), report(0)

      { m_textEdit = new QTextEdit(this); setCentralWidget(m_textEdit); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(generateReport())); timer->start(1000); }

      private slots:
      void generateReport()

      { static int count = 0; QFont f; f.setPointSize(12); QTextDocument *oldReport = report; report = new QTextDocument(this); // report->setDefaultFont(f); // this always works QTextCursor tc(report); tc.insertText(QString("Hello Qt %1!").arg(++count)); m_textEdit->clear(); m_textEdit->setDocument(report); m_textEdit->setFont(f); // only this doesn't the second time delete oldReport; }

      private:
      QTextEdit * m_textEdit;
      QTextDocument *report;
      };

      #include "main.moc"

      int main(int argc, char * argv[])
      {
      QApplication app(argc, argv);
      MainWindow mainWindow;
      mainWindow.show();
      return app.exec();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            vhilshei Volker Hilsheimer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes