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. QComboBox with a star icon to "pin" favorites
QtWS25 Last Chance

QComboBox with a star icon to "pin" favorites

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 296 Views
  • 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Imagine you have a 50+ items QComboBox and most of the time you use the same 3 items.
    I would like to show a star icon ⭐when hovering on a list item, clicking this star will mark the item as a favorite and show it at the beginning of the list.

    I think I know how to show favorites on top, once they are marked.
    But I'm not sure where to start in order to display the ⭐icon on the right side of currently hover item and receive an event when this ⭐is clicked.

    It seems the way to go would be to write my own ItemDelegate, is that correct?
    As anything similar (with other kind of QWidgets) already be done? I found QComboBox with checkboxes but they use a checkable property

    Thanks in advance

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

      Hi,

      Sounds like a job for a custom QStyledItemDelegate.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        Thangs @SGaist I'm currently looking at examples here and there.
        From AbstractItemDelegate documentation:

        To provide custom editing, there are two approaches that can be used. The first approach is to create an editor widget and display it directly on top of the item. To do this you must reimplement createEditor() to provide an editor widget, setEditorData() to populate the editor with the data from the model, and setModelData() so that the delegate can update the model with data from the editor.

        The second approach is to handle user events directly by reimplementing editorEvent().

        Will I be able to enter editor mode on mousehover if I go with solution one?
        With solution2 the difficult part seems to be able to prevent the QComboBox to collapse when the star is clicked, and properly retrieve clicks on the star

        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