Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Implementing QComboBox in a QTreeView item
Forum Updated to NodeBB v4.3 + New Features

Implementing QComboBox in a QTreeView item

Scheduled Pinned Locked Moved Language Bindings
1 Posts 1 Posters 1.2k 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.
  • Y Offline
    Y Offline
    ynvb
    wrote on last edited by
    #1

    Hi,
    I am new to QT and currently working on a python GUI application using PySide.

    I have implemented a QStandardItemModel with my data and QTreeView to display it.
    I would like to display some of the model indexes as a combobox with multiple selection items. the combobox needs to be always displayed (and not just while editing).

    So, after digging up I came up with the conclusion that I will need to implement a delegate (derived from --QStyledItemDelegate)-- that will render my desired indexes to display the Combobox with my data.

    However I cannot seem to be able to actually display the combobox, and always end up with an empty column in my treeview.

    This is a simplified version of my code:

    @
    class TreeViewDelegate(QtGui.QStyledItemDelegate):

    def init(self, parent):
    QtGui.QStyledItemDelegate.init(self, parent)

    def paint(self, painter, option, index):
    my_val = index.data(role=MyValRole)
    if my_val is not None:
    combo_opt = QtGui.QStyleOptionComboBox()
    combo_opt.rect = option.rect
    combo_opt.state = QtGui.QStyle.State_Enabled
    combo_opt.frame = True
    combo_opt.currentText = my_val
    QtCore.QApplication.style().drawComplexControl(QtGui.Qstyle.CC_ComboBox, combo_opt, painter, QtGui.QTreview())

        else:
           QtGui.QStyledItemDelegate.paint(self, painter, option, index)
    

    def sizeHint(self, option, index):
    my_val = index.data(role=MyValRole)
    nameFont = QtGui.QFont(option.font)
    nameFM = QtGui.QFontMetrics(nameFont)
    name_width = nameFM.width(my_val)
    name_height = nameFM.height()

    return QtCore.QSize(name_width, name_height)
    @

    What am I doing wrong here?
    Any assistance will be appreciated.

    Thanks,
    ynvb

    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