Hello,
Please I will need you help. I am not that proficient with QTableWidget and honestly need your help with proper guidance.
Before I came here, I have made several research but to no avail. I have also studied the Qt documentation but don't understand it.
I have basic knowledge of Python and pyqt5 and have written some projects anyway, my problem is with QTableWidget.
I am writing a program and in one of the windows, a click of a button loads a window with a qtablewidget in it. This qtablewidget displays retrieved records from the database.
Please I need a line of code that can make any selected row of the qTablewidget to be displayed in a particular lineEdit in the same class with the qTableWidget.
I would prefer a code example as an illustration. Please. In the attached photo, you can see the selectedRow label and its QLineEdit which is readOnly, please I want the content of the selectedRow in the qtablewidget to display in that QLineEdit.
Kindly help me with code based on my codetabw.jpg
The below is an extract from my program:
[ATTACH
=CONFIG
]13697[/ATTACH
]displaylb
= QLabel("Selected row") self.displaytx.setReadOnly(True)
Headerlist = [this contains the columns title in the qTablewidget]
self.tab.setRowCount(100000)
self.tab.setColumnCount(15)
self.tab.setHorizontalHeaderLabels(Headerlist)
self.tab.horizontalHeader().setStyleSheet("::section{background-color: blue}")
self.tab.setGeometry(150, 200, 1700, 1700)
self.tab.resizeColumnsToContents()
#self.tab.setColumnWidth(0,150)
self.tab.horizontalHeader().setSectionResizeMode(
QHeaderView.
Stretch) # this makes the columns fit in the widget self.
tab.
setEditTriggers(QtWidgets.
QTableWidget.
NoEditTriggers) self.tab.cellDoubleClicked.connect(self.tabClick)
[ATTACH=CONFIG]13697[/ATTACH]displaylb = QLabel("Selected row")
self.displaytx = QLineEdit()
self.displaytx.setReadOnly(True)
self.tab = QtWidgets.QTableWidget(self)
Headerlist = [this contains the columns title in the qTablewidget]
self.tab.setRowCount(100000)
self.tab.setColumnCount(15)
self.tab.setHorizontalHeaderLabels(Headerlist)
self.tab.horizontalHeader().setStyleSheet("::section{background-color: blue}")
self.tab.setGeometry(150, 200, 1700, 1700)
self.tab.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.tab.resizeColumnsToContents()
#self.tab.setColumnWidth(0,150)
self.tab.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tab.horizontalHeader().setSectionResizeMode(
QHeaderView.Stretch) # this makes the columns fit in the widget
self.tab.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
self.tab.cellDoubleClicked.connect(self.tabClick)
To copy to clipboard, switch view to plain text mode
Bookmarks