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

QFontComboBox displays incorrect font on first load.

    XMLWordPrintable

Details

    Description

      Something funny is going on with QFontComboBox and setting the current font to the default font. The combo box display does not match up with currentFont(). This is especially troublesome if the user accepts the default font, because currentFont() will return a different value than what is displayed in the combo box.

      main.cpp
      #include <QApplication>
      #include "widget.h"
      
      int main(int argc, char **argv) {
        QApplication app(argc, argv);
        MyWidget w;
        w.show();
        return app.exec();
      }
      
      widget.h
      #ifndef WIDGET_H
      #define WIDGET_H
      
      #include <QtDebug>
      #include <QFontComboBox>
      #include <QTimer>
      #include <QVBoxLayout>
      #include <QWidget>
      
      class MyWidget : public QWidget {
        Q_OBJECT
      public:
        explicit MyWidget(QWidget *parent = NULL) : QWidget(parent) {
          QVBoxLayout *layout = new QVBoxLayout;
          font_box_ = new QFontComboBox;
          layout->addWidget(font_box_);
          setLayout(layout);
          QTimer::singleShot(3000, this, SLOT(ChangeToDefaultFont()));
        }
      private slots:
        void ChangeToDefaultFont() {
          QFont default_font;
          qDebug() << "default_font" << default_font;
          font_box_->setCurrentFont(default_font);
          qDebug() << "font_box_->currentFont()" << font_box_->currentFont();
          QTimer::singleShot(3000, this, SLOT(ChangeToOtherFont()));
        }
        void ChangeToOtherFont() {
          QFont other_font("Arial");
          qDebug() << "other_font" << other_font;
          font_box_->setCurrentFont(other_font);
          qDebug() << "font_box_->currentFont()" << font_box_->currentFont();
          QTimer::singleShot(3000, this, SLOT(ChangeToDefaultFont()));
        }
      private:
        QFontComboBox *font_box_;
      };
      
      #endif // WIDGET_H
      

      My output for the first three iterations, with comments. (It repeats the last two iterations after this.)

      default_font QFont( "Sans,10,-1,5,50,0,0,0,0,0" )
      font_box_->currentFont() QFont( "Sans,10,-1,5,50,0,0,0,0,0" ) // !! But combo box displays "DejaVu Sans"
      other_font QFont( "Arial,12,-1,5,50,0,0,0,0,0" )
      font_box_->currentFont() QFont( "Arial,12,-1,5,50,0,0,0,0,0" ) // Correct
      default_font QFont( "Sans,10,-1,5,50,0,0,0,0,0" )
      font_box_->currentFont() QFont( "DejaVu Sans,10,-1,5,50,0,0,0,0,0" ) // Combo box displays "DejaVu Sans," which is in-sync with currentFont(), although the setCurrentFont() was called with Sans

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            dmateer Dave Mateer
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes