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. Tree widget item signals.
QtWS25 Last Chance

Tree widget item signals.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.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.
  • D Offline
    D Offline
    DaveTheBrave
    wrote on last edited by
    #1

    I'm trying to make doubleclicking items in a tree widget do things. Code below is Python, but this should apply to C++ QT as well.

    'itemDoubleClicked' is a signal of tree widget, not of a tree item.

    @item = QtWidgets.QTreeWidgetItem(self.ui.tr_owned)
    self.ui.tr_owned.itemDoubleClicked.connect(lambda symbol: hist_data.plot(symbol))@
    The above works, but isn't specific to the item clicked.

    The QT documentation lists its parameters as this: 'void QTreeWidget::itemDoubleClicked(QTreeWidgetItem * item, int column) [signal]'
    @
    item = QtWidgets.QTreeWidgetItem(self.ui.tr_owned)
    self.ui.tr_owned.itemDoubleClicked(item, 4).connect(lambda symbol: hist_data.plot(symbol))@
    This doesn't work: 'TypeError: native Qt signal is not callable'

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi,

      Signals are not "real" methods, so you can't call them. To make your thing, one possibility is to implement a class deriving from both QObject and QTreeWidgetItem. Then you could have signals specific to your items and connect them. Another possible way is to connect the signal of the tree widget to a slot filtering the items (the sending item will be the first parameter of the slot).

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DaveTheBrave
        wrote on last edited by
        #3

        Thank you. Would you elaborate on the second solution? I can't figure out how to determine which item sent the signal.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zakarrrr
          wrote on last edited by
          #4

          This is how in c++ works, maybe gives an idea:

          so define the object:
          @treelist = new QTreeWidget(this);@

          connect the signal to a slot:
          @ connect(treelist, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(listSelected(QTreeWidgetItem*, int)));@

          you can get the item info by column
          @void MainWindow::listSelected(QTreeWidgetItem *item, int column) {
          QString sitem = item->data(column, Qt::DisplayRole).toString();
          ...
          }@

          If a person is doing things behind you, he s clearly an ...
          Because he is an ..., he will tell any stories, which will make you think he is ok! -.-

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DaveTheBrave
            wrote on last edited by
            #5

            Thank you - I got it working based on y'alls advice. "the sending item will be the first parameter of the slot" was the key bit.

            @self.ui.tr_owned.itemDoubleClicked.connect(self.dclick)

            def dclick(self, item):
            hist_data.chart(item.text(0))@

            Another working solution involved picking the item that's selected, but this is more elegant, since the treeitem seems to be passed implicitly as the first argument.

            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