Qt Forum

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

    Qt Academy Launch in California!

    Solved QTableview index issue

    General and Desktop
    3
    6
    478
    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.
    • K
      kprice last edited by

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

        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 Reply Quote 4
        • K
          kprice last edited by

          Thank you so much.

          1 Reply Last reply Reply Quote 0
          • K
            kprice last edited by

            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?

            mrjj V 2 Replies Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @kprice last edited by mrjj

              @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 Reply Quote 4
              • V
                VRonin @kprice last edited by

                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 Reply Quote 4
                • First post
                  Last post