[PyQt] Scripted selection of items in QTableView

Florian Bruhin me at the-compiler.org
Tue Aug 2 21:02:13 BST 2016


* Saeed Bakhshmand <saeedbakhshmand at gmail.com> [2016-08-02 15:25:25 -0400]:
> Hello Experts,
> 
> Here is a part of my code:
> b= qt.QTableView()
> model = qt.QStandardItemModel()
> b.setModel(model)
> # ....set up of table with importing data for the items of the model
> 
> I easily can access to the indices of the manually selected (clicked) items
> by sel_mode = b.selectionModel() and sel_mode.selectedIndexes().
> I am wondering if I can somehow import a default set of selected items in
> the table using a python command? In this way a group of per-determined
> cells in the table will be selected prior to user's interactions.
> b.setSelection() seems the right choice but I am not sure. Would appreciate
> any hints.

setSelection seems to be for all items in a QRect, which doesn't sound
like what you want.

However, the selectionModel() has a select() method which takes a
QModelIndex (plus flags) - that sounds more like what you want.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160802/e639c2b6/attachment.sig>


More information about the PyQt mailing list