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. PyQt: Combobox with checkable items (no external libs)
Forum Updated to NodeBB v4.3 + New Features

PyQt: Combobox with checkable items (no external libs)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.6k Views 1 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.
  • B Offline
    B Offline
    beefmusta
    wrote on last edited by
    #1

    I'm trying to make a combobox with checkable items. So far I've made a model that inherits from QAbstractTableModel, returns the Qt.ItemIsUserCheckable flag and handles the Qt.CheckStateRole in data(). Everything works fine when using a tableview on the model (checkboxes with labels in the first column). However when I point a QComboBox to the model, only the labels are displayed in the list i.e. no checkboxes. Can anyone offer suggestions on how to get this to work?

    Something like what is described in this post is what I'm after: http://www.qtcentre.org/archive/index.php/t-14639.html

    External libraries (e.g. Qxt) aren't an option. Also I need to use a Model/View approach rather than manually adding items, so the method of using a QMenu with checkable QActions is less than ideal.
    Thanks!

    1 Reply Last reply
    1
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      If using libQxt isn't an option (why not? It's licence is very liberal), then you can at least use it for inspiration. It is open source, and it has a working example of exactly what you are after.

      Sure, it's API is based on that of QComboBox, but I am sure you can easily figure out how you can use a normal item view from those sources.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beefmusta
        wrote on last edited by
        #3

        Thanks Andre, the main reason is that QxT bindings for Python aren't readily available. All I'm after is a widget that allows items from a model to be selected and that uses a minimum of screen real-estate (hence why a combobox would be good!) I will look into the Qxt source and possibly an alternate widget to do the same thing.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          beefmusta
          wrote on last edited by
          #4

          I solved the problem - the custom model with checkstate role supported was working all along. It turns out checkboxes were just not being rendered when using Gnome under Ubuntu (10.04). Checkboxes are rendered correctly when using KDE or Windows XP. This must be a bug in Qt.

          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