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. Combobox with checkable items issues

Combobox with checkable items issues

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.0k 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.
  • V Offline
    V Offline
    voltron
    wrote on last edited by
    #1

    Hi all.

    I need to implement QComboBox with checkable items. As I understand, this can be done by using QStandardItemModel and QStandarItem with corresponding flags set.
    I successfully implemented this, but my code works only in some systems/ desktop environments. For example, it works under WIndows XP/7 and 10, as well as in KDE. But it does not work in Gnome and some window managers (I tested with OpenBox). Is this Qt bug or something wrong with my code? Should I submit a ticket?

    Here is small example to reproduce

    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    
    data = ['item 1', 'item 2', 'item 3']
    
    class Example(QComboBox):
        def __init__(self):
            super(Example, self).__init__()
    
            self.model = QStandardItemModel(len(data), 1)
            for i, f in enumerate(data):
                item = QStandardItem(f)
                item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                item.setData(Qt.Unchecked, Qt.CheckStateRole)
                self.model.setItem(i, 0, item)
    
            self.setModel(self.model)
            self.show()
    
    
    def main():
        app = QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    P.S. I searched in forum and found similar issue in this old thread https://forum.qt.io/topic/11769/pyqt-combobox-with-checkable-items-no-external-libs

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

      Hi,

      It wouldn't surprise me that this design is running against the Human Interfaces Guidelines of these window managers.

      Out of curiosity, what do you need such a special combo box for ?

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

      V 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        It wouldn't surprise me that this design is running against the Human Interfaces Guidelines of these window managers.

        Out of curiosity, what do you need such a special combo box for ?

        V Offline
        V Offline
        voltron
        wrote on last edited by
        #3

        Thanks for your reply @SGaist.
        I just checked Gnome HIG and seems it allows such kind of controls.

        I need special combobox because there are variable list of options and user should be able to select multiple options. Also as this list can be relatively long I don't want to use listbox and make my dialog bigger.

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I would use list-box. It does not have to be as big as the number of the entries (a scrollbar will be shown if it is smaller). It is really unusual and confusing to have check-boxes inside a combo-box.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply
          0
          • jsulmJ jsulm

            I would use list-box. It does not have to be as big as the number of the entries (a scrollbar will be shown if it is smaller). It is really unusual and confusing to have check-boxes inside a combo-box.

            V Offline
            V Offline
            voltron
            wrote on last edited by
            #5

            @jsulm yes, I know that ListBox have scrollbars. But behavior I described is a bug, isn't it?

            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