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. QTableview index issue

QTableview index issue

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 923 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.
  • K Offline
    K Offline
    kprice
    wrote on 12 Jun 2018, 15:48 last edited by
    #1

    Using PyQt5, one feature of my application is that there is a QTableView that dynamically increases the number of rows it has. Each column has a different purpose, widgets, text entries, etc. One such columns has QComboBoxes with 3-4 entries (but potentially more in the future). What I want to be able to do is when the user selects one of the indices from the combo box, I want the adjacent cell (same row, different column) text entry to be disabled. The problem is that all of the signals from QComboBox point to the index of the item selected in the combo box itself, so I have no way of knowing which row (in the whole table) is selected, therefore after I determine which index in the combo box was changed (with currentIndexChanged), I don't know which row in the table to apply the change to. Because there is a dynamic number of rows, I can't just make a new signal for each new row. Any help would be appreciated.

    Thanks,
    kprice

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 12 Jun 2018, 15:51 last edited by
      #2

      Don't use setItemWidget.

      Subclass QStyledItemDelegate to use a combobox and set that delegate to the column you want. then conncet to the dataChanged signal of your model and if the changed index is in the column with the combos decide what to do

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • K Offline
        K Offline
        kprice
        wrote on 12 Jun 2018, 16:20 last edited by
        #3

        Thank you so much.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kprice
          wrote on 12 Jun 2018, 16:30 last edited by
          #4

          On and unrelated question, when setting flags, for instance ".setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)" and "setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable)" , are the | and & characters acting like logical ORs and ANDs? Like does it take the current value of of the flags and use that to compute the values of all of them? For instance, in the first example, if currently ItemIsEditable is true and the ItemIsSelectable is false, would it set them both to true b/c they're ORed?

          M V 2 Replies Last reply 12 Jun 2018, 16:43
          0
          • K kprice
            12 Jun 2018, 16:30

            On and unrelated question, when setting flags, for instance ".setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)" and "setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable)" , are the | and & characters acting like logical ORs and ANDs? Like does it take the current value of of the flags and use that to compute the values of all of them? For instance, in the first example, if currently ItemIsEditable is true and the ItemIsSelectable is false, would it set them both to true b/c they're ORed?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 12 Jun 2018, 16:43 last edited by mrjj 6 Dec 2018, 16:43
            #5

            @kprice
            Yes its OR AND , NOT (negate)
            ( i assume its the same for python as for c++ :)

            so
            setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)
            Sets both
            setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable

            Take current flags and mask out both ItemIsEditable and ItemIsSelectable
            (if set)

            1 Reply Last reply
            4
            • K kprice
              12 Jun 2018, 16:30

              On and unrelated question, when setting flags, for instance ".setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)" and "setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable)" , are the | and & characters acting like logical ORs and ANDs? Like does it take the current value of of the flags and use that to compute the values of all of them? For instance, in the first example, if currently ItemIsEditable is true and the ItemIsSelectable is false, would it set them both to true b/c they're ORed?

              V Offline
              V Offline
              VRonin
              wrote on 12 Jun 2018, 16:43 last edited by
              #6

              They are bitwise operators AND/OR

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              4

              1/6

              12 Jun 2018, 15:48

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved