I need to determine which rows are selected in association with someone. From the scene, I call the function to get the selection. I want to call the function, from that object that gives this function object. This function takes two arguments: the row I want to test, and a You The model is used by item models, delegates and selection models to find an item in the model ... with parent argument, which is one. This is where I am lost What is it
parents for reasoning? Where does it come from? Conceptually, I do not understand why I needed this parameter, and firmly, I do not know which work function I should go to work on.
parent to
QTreeView , example In the case of your use, it is the relevant parts of the documentation:
While referencing top-level items in a model, invalid indexes are often used as the original index Land. " QtCore.QModelIndex () will create an invalid index, which argues that you are looking for. In this example, you select the rows To print the situation, you can use the context menu:
# ./UIR / bin / NYY Python # - * - Coding: UTF-8 - * - Import from QTGui , Kyutikor Class Mayvando (QtGui.QTableView): def __init __ (self, not the original = no): Super (Mayvando, .__ (ini row number itself) range (3) t) __ (self.modelSource = QtGui.QStandardItemModel (self) to the original): column item number ([3]): Item = QtGui.QStandardItem () item.setText ( "row: {0} column: { 0} ". format (row number, column number) items. Append (items) SelfkmodelSourcekappendRow (items) self .actionselectedRows = QtGui.QAction (self) SelfkactionSelectedRowsksetText (" Select the lines ") self .actionSelectedRows.triggered.connect (self.on_actionSelectedRows_triggered) self.contextMenu = QtGui.QMenu (self) self.contextMenu.addAction (auto.actionselectedRows) self.setModel (self.modelSource) self.setContextMenuPolicy (QtCore.Qt.CustomContextMenu) self .setSelectionBehavior (QtGui.QAbstractItemView.SelectRows) self.horizontalHeader (). SetStretchLastSection (True) self.customContextMenuRequested.connect (self.on_customContextMenuRequested) @ QtCore.pyqtSlot (bool) def on_actionSelectedRows_triggered (self-state) in the range of line numbers (self.model (). RowCount ()): info = " row {0} ".format (rowNumber) if self.selectionModel () Kaiarro selected (line number, QtCore.QModelIndex ()): info + =" selected "else: info + =" not selected "print info @ QtCore .pyqtSlot (QtCore.QPoint) DF on_customContextMenuRequested (self, position): Self ContextMenu.exec_ (self.mapToGlobal (pos)) If __name__ == "__main__": import sys app = QtGui.QApplication (sys.argv) app.setApplicationName ('MyWindow') Main = MyWondo () Main. Position (333, 222) main.show () sys.exit (app.exec_ ())
No comments:
Post a Comment