Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved Combobox with checkable items issues

    General and Desktop
    3
    5
    1705
    Loading More Posts
    • 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
      voltron last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • V
          voltron @SGaist last edited by

          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 Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • V
              voltron @jsulm last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post