Question: I have a QTableView in PyQT5 / PySide2
I want to * Know if a row is selected (my tableview is set to select by rows) * Know which row is selected
Thanks
Answer:
A bit hackishly though:
select = tableview.selectionModel()
selected = select.selectedRows()
if selected:
print(selected[0].row())
but that does it well:
selected = select.hasSelection()
Written by
Abdur-Rahmaan Janhangeer
Chef
Python author of 7+ years having worked for Python companies around the world
Suggested Posts
Pyside2 / PyQt5 Extract Data From QFormLayout
import sys from PySide2 import QtCore from PySide2 import QtWidgets from PySide2 import QtGui cla...
Packaging An Sqlite db-included CRUD PyQt5 app using PyInstaller
The Python programmer’s journey inevitably leads him to one of the black belts of the industry: pack...
Python EFL: Building Custom Elementary Widgets (2026)
Want to create unique UI components tailored to your app’s needs? This Python EFL tutorial teaches y...