简体   繁体   中英

How to deselect an entire QTableWidget row

Given the row index, how can I deselect a single row in a QTableWidget? I don't want to deselect everything using clearSelection()

You can use the table selectionModel() and its select() function, using the Deselect and Rows flags:

    def deselectRow(self, row):
        if row > self.table.rowCount() - 1:
            return
        selectionModel = self.table.selectionModel()
        selectionModel.select(self.table.model().index(row, 0), 
            selectionModel.Deselect|selectionModel.Rows)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM