Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
4.6.3, 5.5.1
-
None
-
Ubuntu 10.04
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.
#include <QApplication> #include "widget.h" int main(int argc, char **argv) { QApplication app(argc, argv); MyWidget w; w.show(); return app.exec(); }
#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