QFontDatabase::styles(const QString & family) Returning Non Existent Style Data.



  • Hello,

    I'm working on a form which has two combo boxes, one QFontComboBox and a second combo box which I populate with the styles after a font is chosen. The code I have to set the styles box after a font is selected is:

    @
    void AddNewFont::fontChanged(const QFont& font)
    {
    //get the available styles from the QFontDatabase and load into the styles combo
    QFontDatabase fdb;
    QComboBox * combo = this->ui->styleCombo;

    combo->setEnabled(true);
    combo->clear();
    combo->addItems(fdb.styles(font.family())); //add the list of styles
    //select the first item
    if(combo->count() > 0)
    combo->setCurrentIndex(0);
    else
    combo->setEnabled(false);

    }
    @

    This code works in populating the styles combo box, but for some fonts it is returning too many styles. For example I have the font "Garamond Premr Pro Smbd" whose only style is "Semibold", yet fdb.styles(font.family()) returns, "demibold" "demibold italic" "bold" and "italic". This problem has occurred with multiple other fonts as well. Has anyone else had a similar issue or know what I'm doing wrong that these incorrect styles are being returned?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.