Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFontComboBox::removeItem(int) has no effect

QFontComboBox::removeItem(int) has no effect

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 456 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    I need to filter the choices in a QFontComboBox and limit the selection list to about 10 font families that are understood by the GraphViz library. I called QFontComboBox::setWritingSystem with QFontDatabase::Latin as argument but still have 154 fonts to choose from.

    Apparently, the list is not editable because calling removeItem has no effect. I also tried to get the model and called removeRow on the model, but still nothing changes.

    Is there another way except to derive my own font combo box from QComboBox? I think it shouldn't be too hard to do, but I don't enjoy "re-inventing the wheel".

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      I wonder if a QSortFilterProxyModel could do it. ( Nope, it wont )
      https://stackoverflow.com/questions/22454264/how-to-filter-the-data-of-qcombobox
      The last code.
      override bool filterAcceptsRow( int source_row, const QModelIndex& source_parent )
      and skip those with wrong famlies.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        Good idea @mrjj but wont work.
        I have no idea why but instead of adding the model as a private member to QFontComboBox they decided that casting QComboBox::model() worked just as well.

        I think this is a limitation due to bad design of QFontComboBox so I opened a bug report to get the model stored as a private member allowing, going forward, the solution above to work

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • R Offline
          R Offline
          Robert Hairgrove
          wrote on last edited by
          #4

          @mrjj and @VRonin : Thank you for your suggestions. In the meantime, I have decided to implement my own font combo box which derives from the standard QComboBox class. I only had to create my own model class deriving from QAbstractListModel, and it seems to work OK for my present situation.

          The only unexpected thing was that I had to override the QAbstractListModel::match() function because it is called by QComboBox::findData(). Otherwise, it was fairly easy.

          I never really liked the QFontComboBox anyway, because most of the fonts appear too large in the list. Besides, there are numerous quirks such as when calling QFontComboBox::setCurrentFont() it doesn't set the font for the line edit control. You must call QFontComboBox::setFont() as well if you want the text of the font family to appear in the chosen font when the list is not shown.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved