Qtablewidget get row data

Qtablewidget get row data

I can't use QTableView and QtSql unless I can find a way to use it with an SQL query, get every selected record into a list, and stop certain columns from being edited. This uses removeRows () internally. Now I need to highlight the first row, since it shows the accurate search result. I am getting data from an excel sheet. I have a QTableView as follows: 1 a1 b1 c1 2 a2 b2 c2 3 a3 b3 c3 I know how to get the item's text of the selected ones as a list. I want to make rows clickable and when clicked I need to check the hidden comlumn in order to retreive the information from mysql based on it's ID in order to modify or delete the row below is Aug 5, 2011 · Doing something like this should work: tableWidget->insertRow( tableWidget->rowCount() ); This will append a row to the end of your table. Read the documentation here. Iterate over the columns of those rows. I have implemented a search functionality. row() for index in self. Jul 24, 2021 · How to get rows data from a QTableWidget Column? 0. row = table. QTableWidgetItem *QTableWidget::item (int row, int column) const. text() Nov 17, 2016 · A QTableWidgetItem has a method called row (): http://doc. table_model5. selectedIndexes()} output = [] May 6, 2010 · 6. Get state of checkbox cellWidget in QTableWidget PyQT. getClickedCell) The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. rows = {index. In your case, you probably have created a table with a size of 1 row Feb 14, 2016 · 4. Here's a simple demo script: from PyQt4 import QtGui, QtCore. Mar 1, 2013 · I have a QTableWidget and put a Detail Button on cell QTableWidget how to get The spesific row and column while i click The Button Detail in the cell QTableWidget. QAbstractItemView. tableWidget. myTable. I want to implement functionality that whenever a row is selected and then the user presses a button, I should be able to get the first column of that selected row. Interesting, that a very similar approach works in PyQt4 (I am actually porting a previously written PyQt4 code to PyQt5). I seem to be unable to select a cell and get the text out of it and wanted to see why it won't retrieve it. A table is an arrangement of data in rows and columns and widely used in communication, research, and data analysis. column()). You need to connect the clicked signal to your own MyClass::onTableClicked() slot, as shown below: Sep 7, 2016 · setData(Qt::UserRole, myData); // set. The code is in python 3. You’ll understand how the layout of the TableWidget works in this example. text() self. table->setRowCount(0); You could also clear the content and then remove all rows. That is, the user can drag and drop one entire row, moving it up or down in the table to a different location in between two other rows. int QTableWidget::currentColumn() const Returns the column of the current item. itemAt(0,0). If you need more than one you can use Qt::UserRole + 1, + 2, and so on ( Qt::UserRole is "The first role that can be used for application-specific purposes. Jul 8, 2015 · Qt C++ Get data from a selected row of a table view. exec_() If you type a search string in the line input, you'll see the first matching item in the table selected (and highlighted) like below. setItem(row, 0, item) self. dlg, "", "/desktop") Feb 14, 2019 · QTableWidgetItem ( (data [row] [column])) = value which you will set in QTableWidget. The goal is illustrated in this figure: What I tried, and what happens. tbl_anggota. item(current_row, current_column). Starting off where you leave the data, here is how to fill the QTableWidget from the data: Sep 27, 2020 · w = MainWindow() w. what I can do right now is Retrive the Text using qDebug: @ for (int i=0; i<table->rowCount(); ++i) Apr 21, 2017 · I'm Beginner in python I want to display the seconde data in QtableWidget what i should change in 1st code to make data display or another way Thank you so much python Apr 6, 2013 · 7. It's based on the size hint for the row, which is derived from the size hint for the item delegate (amongst other things). selectionModel(). Apr 15, 2015 · How to delete widgets from gridLayout. May 17, 2021 · 6. QTableWidgetItem(str(data[row][col])) self. Qt. tableview=QTableView() self. Jan 11, 2012 · Try using the method. ", you can read more about the Feb 22, 2018 · self. Dec 13, 2013 · address_selection (err); ui->tableWidget-> setItem (current_row, 0, new QTableWidgetItem (err)); //ui->tableWidget->setItem(current_row,0,new QTableWidgetItem("x")); break ; Let say current_row = 9. join(item[0] for item in rows_pong) with data = [item[0] for item in rows_pong] and change lista = [data] to lista = data if you want each IP to show up in a new row. The code you have posted could be used where given you had a widget, a ComboBox, whose position on the Table(in terms of row and column) the program was unaware of, and you wanted to find out the QModelIndex(from which you could get the row), on the TableWidget, where it could have been positioned. I want to extract the data from a table when selected. class Ui_MainWindow(object): Apr 11, 2020 · I want to populate a QTableWidgetwith incoming data from user input this function should insert each incoming input row by row in "real time" , so far its inserts the input in all rows at the sam Mar 16, 2017 · field1 = self. – In this example we’ll be creating a PyQt QTableWidget filled with values as well. Instead of that it must be 65. Can i get the row index and id of the table from the qtablewidget? def datails( Jul 30, 2012 · Not sure if it was intended but lista consists of one item since you are joining the results of the query into a single string. class Window(QtGui. Subclass QAbstractItemModel and implement data() (for reading), and all the other functions you need from the documentation. Feb 25, 2017 · In my layout, my dynamically generated QTableViews seem to get resized to only show one row. EDIT 2 Mar 16, 2015 · I need to read the values entered in the cells in the QtableWidget. QPushButton(text, self. for (int cidx = 0 ; cidx < 'number of Feb 24, 2012 · form_shift is form name tblSession is QTableWidget object shift_id=form_shift. table) self. This is the trickiest part, but refer to the above link for a walkthrough of how to do this. in the picture above, what I currently got is: Once row 1 is selected, the button (2) will become available to click, and it will load up a new window. It is much easier than trying to get the data back from another system (QTableWidget in this case) and parsing it. Where myData is a supported QVariant type. cellClicked. If you want to continue using a table, a somewhat cleaner solution than adding dummy items would be to use a persistent model index: button = QtGui. Use QTableWidget. getExistingDirectory(self. try: _fromUtf8 = QtCore. It returns the row number in which the item is located. I am getting the following error: AttributeError: 'module' object has no attribute 'QTableWidgetItem' My code: Nov 30, 2015 · How to get rows data from a QTableWidget Column? Hot Network Questions Episode of a sci-fi series about a salesman who loses the ability to understand English Feb 18, 2020 · I am using QTableWidget to show the data. Feb 15, 2020 · I do not do it with a LineEdit because I need the number of spaces to fill out equal to those of a listWidget. If you want to use showRow then you may need to clear filter, hide all rows and show rows with 2 and 3. verticalHeaderItem() with the table's current row. rowCount() #necessary even when there are no rows in the table. The selection method is that entire row is selected. the code is the following: def Input_shape (self): filefolder= QFileDialog. insertRow(currentRowCount, 0, QTableWidgetItem("Some text")) To clarify the last line of code, the first parameter of insertRow() is the current row Jan 9, 2014 · I am working in Qt 4. fromUtf8. I found this solution,which works fine with numbers but with text the programm collapses. QWidget * QTableWidget:: cellWidget ( int row, int column) const. first(); Oct 18, 2013 · Here is an example of how you can get a table cell's text when clicking on it. text()) for i in range(col_count)] # df indexing is slow, so use lists df_list = [] for Oct 1, 2020 · I found the answer. by clicking a "Clear Table" button), you can call the following function: self. 2. The row and column specified is the cell that was pressed. Chris. Returns the widget displayed in the cell in the given Nov 13, 2021 · Filter removes data before sending to TableView, showRow() / hideRow() removes row directly in TableView. This example will mainly be featuring the below method, setItem(). currentRow() label = table. currentRow() current_column = self. I have a QStringList which I need to populate with the value from a specific column, let's say the second, of each row. clicked. QTableView (and other Model/View widgets) is preferable for displaying a significant amount of data. append(str(self. int QTableWidget::currentRow() const Returns the row of the current item. note: you cant pass datetime into QTableWidgetItem , because of that you need to check if value you are trying to set into May 11, 2020 · PyQt5 – QTableWidget. A QTableView implements a table view that displays items from a model. To get the currently selected row, use QTableWidget. In this article, we will learn how to add and work with a table in our PyQt5 application. g. resizeRowsToContents affects the existing rows with contents. It's really easy to start with QStandardItemModel: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {. Used like this: 'addRow(self)' to create and populate a row on QTableWidget with values from QLineEdit. Item(row, 0) but doesn't work. Once I have populated a QTableWidget with data, I set No. insertRow(0) item = QtGui. Everywhere I research gives the code; # Get the first column and first row of table self. value, a3. model() and You will get QAbstractTableModel object. 9. setModel(), You will get TypeError: QTableWidget. So You are stuck with item based data handling, if You keep using QTableWidget. One way that worked in my situation was. setRowCount(0) The code you've provided oddly works but isn't populating data into the table anymore. The following example allows only single selection of a row: m_pTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); m_pTableWidget->setSelectionMode(QAbstractItemView::SingleSelection); Handling signals Dec 20, 2015 · I am working on a small library application. For a better understanding of the concept Jul 6, 2020 · It works so far that the Table is filled and it looks right. data() So i ended up using this which worked to get the value from the same index row but column5 of the selection. setCellWidget(row, 1, EditButtonWidget()) Where the nb_col is always two, and the nb Feb 11, 2017 · @Karoluss96 said in Get content of cell from QTableView: It take only the first record from selected row. Describe alternatives you've considered Manually reading the DOM and getting the correspondent tr for the index I have. QWidget): def __init__(self, parent=None): May 26, 2022 · In this part of the code I correctly find through a button the row number and the column number of the last item changed by the user, how can I store in a variable the item that has column 0 and as row the "row" variable declared? I tried this tabella_registrazioni. Then you increment current_row and set data for row 10 which is out of table index. for (int ridx = 0 ; ridx < 'number of rows' ; ridx++ ) {. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: pow(row, column+1))); tableWidget->setItem(row, column, newItem Mar 4, 2018 · At other times I will be working with mulitiple rows using: self. Example of handling double click of a cell: connect ( m_pTableWidget , SIGNAL ( cellDoubleClicked ( int , int ) ), this , SLOT ( cellSelected ( int , int ) ) ); Jul 13, 2021 · There's no direct way to do so, and there's no "shortcut" (unless you're absolutely certain that if a certain row/column combination is empty, the following rows and columns are empty too). 1) before filling the table, turn off sorting: table. Remember that hidden columns still count. Mar 4, 2022 · I have a qtablewidget with mysql table, and in the last column one button that i want to click to get the row index. QTableWidgetItem(username) self. model(), one can shortcut getting at a column in the same row via. fontMetrics(). text() field2 = self. item(r,0). I use the following code to retrieve the data from the selected cell: row = self. On my self. ui->setupUi(this); Aug 10, 2012 · 5. for index in indexes: Mar 25, 2020 · Extract the data from table when selected. try to do it with QTableWidget itemAt but the return is a QTableWidgetItem. currentRow(): # self. value] How can I do that? Jun 4, 2013 · 5. answered Aug 5, 2011 at 14:48. You set rowCount = 10, so table indexes are 0. 6 and pyqt5. However, it shows: identity[row]. It takes three main arguments, the row index, the column index, and a QTableWidgetItem object. Describe the solution you'd like A method on the QTable to retrieve the row data based on the row index. [signal] void QTableWidget:: cellDoubleClicked (int row, int column) This signal is emitted whenever a cell in the table is double clicked. columnCount() row_count = table. The following assumes that you intend an "empty" item as an item that has no value set (including items that have been modified and then "cleared"). selectedRows() and then for example to print the contents of the 2nd column of the selected rows: python. item(r,1). item(1,0). Mar 30, 2022 · Qt - Copying a QTableWidget's Data and Paste it in Another QTableWidget. Jul 29, 2012 · the only mod i had to do was to use cause i had tried this index. Hope you all understand my requirement. However, I get 0 and 0! However, I get 0 and 0! So it seems like this might be a problem with QTableView::indexAt() , whether its my usage or some sort of bug. Table widgets can be constructed with the required numbers of rows and columns: tableWidget = new QTableWidget(12, 3, this); Alternatively, tables can be constructed without a given size and resized later: tableWidget = new QTableWidget(this); tableWidget->setRowCount(10); tableWidget->setColumnCount(5); The behavior of the table for selecting rows and cells can be customized using methods setSelectionBehavior and setSelectionMode. userName. from PyQt5 import QtWidgets as qtw. height() + 6 ). row_number, column_number, QTableWidgetItem(str(data))) If you want to clear the table (e. I want to get the selected value in table1 and put it in table2. Jun 5, 2014 · To insert a row, you have to follow something similar to this: tableWidget = QTableWidget() currentRowCount = tableWidget. 1. siblingAtColumn(0) Mar 18, 2020 · You can use QTableWidget. tableWidget_2. If you don't like that specific height, just change it to something more acceptable (e. table. The table can be edited with new rows, columns and different headers. The "standard" row height is what you get when you don't resize to contents. except AttributeError: _fromUtf8 = lambda s: s. For example, if you select 1, table2 I want the whole value of row 1 to be entered and the next row 5 to be added to the row 5. setCellWidget(row, column, button) index = QtCore. setData(QtCore. And then sent to qtablewidget. My existing code is given below. ui->QTableWidget->item(ui->QTableWidget->rowCount(),0)->setText(""); Dec 23, 2013 · When user clicks a vertical header, the clicked row is selected and becomes current by default. Sep 26, 2014 · QTableWidgetItem* item = widget->item(row, column); QString textFromItem = item->data(Qt::UserRole); emit cellChanged(row, column, textFromItem); Of course, previously you have to declare your own signal: signals: void cellChanged(int row, int col, QString text); Your signal can be connected to other slot in the same way as cellChanged(int, int) I would like to get the whole text in all cells and its headears from a Qtablewidget and write it to an dataframe (to export it later to an excel file). tableview. thanks got it Apr 9, 2020 · 3. item(row,3). cellClicked(row, column) to your own slot. So look at your 0 argument which only fetches the data for column 0, and write code to pick up all the columns in the row if that is what you want. UserRole and setData: item. text() Or if cells are selected over multiple rows: Feb 27, 2018 · I'm trying to build a very simple application using pyqt5, I have a tableWidget with 5 rows the first row is hidden that has the ID from MySQL database. verticalHeaderItem(row). This can be done at the creation of the table object (in the constructor), or changing the size of the table before inserting items. from PyQt4 import QtCore, QtGui. rowCount() headers = [str(table. Returns the number of rows. Sep 4, 2019 · @phoenix_mashhad To save from keep repeating self. text()) Oct 28, 2020 · To change the variable based on the selected row, you can connect the signal QTableWidget. Sep 13, 2012 · How insert data to qtablewidget row by row. Thus, it would seem from the documentation, you can insert a row at the beginning ("top") of your table with that exact line of code ui->myqtablewidget->insertRow(0); assuming ui and myqtablewidget are declared properly. The Code for the items in the Table: for row in range(nb_row): for col in range(nb_col): item = QtWidgets. I'm using: ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); for highlighting the selected row. I want to have the container of the table views to have a scrollbar instead of the individual table views, which should show full contents. This class is used to provide standard tables that were previously provided by the QTable class, but using the more flexible approach provided by Qt's model/view architecture. Jul 13, 2012 · I've been trying to use QT4 with a QTableWidget to store data. sold_items_details_table. UserRole, data). text() 2. In that new window, I want to query 3 tables in my database for that Test_Identifier found in The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. setSelectionMode(QtGui. The simple way to delete rows is to set the row count to zero. tableWidget. qt. data() with the column set to 5 but it did not work index. setDefaultSectionSize affects the future rows which have not yet been inserted. You simply need to specify where you want the row placed. dropMimeData (self, int row, int column, QMimeData data, Qt. QString. horizontalHeaderItem(i). tableView5. currentIndex(). import random. table->clearContents(); table->model()->removeRows(0, table->rowCount()); Both snippets leave the headers untouched! Aug 4, 2011 · Use a QTableView instead of a QTableWidget. Dec 22, 2015 · Generate your QTableWidget and fill it with the data; How you read the headers depends somewhat on your expectations, if you make no assumptions about the input data, then you will have no headers. MultiSelection) The code below works, but only when the first row is selected. (since i have 128 items, the first 64 items goes to the first table and the remaining 64 items should be placed in the second Table). NewIndex = self. So far I have this: Jan 17, 2015 · 15. I hope that you don't want to do something surprisingly different on header click because it would ruin user experience. html#row. To capture the event of the pressed enter key you must use QShortCut, to obtain the selected items you must use the selectedIndexes() method of the QTableWidget as shown below: from PyQt5 import QtCore, QtGui, QtWidgets. In conclusion, I would like to make table1 show the selected row value in table2. io/qt-5/qtablewidgetitem. May 8, 2017 · I'm having a QTableWidget with 9000 data. DropAction action) Handles the data supplied by a drag and drop operation that ended with the given action in the given row and column. if you allow word wrap for example, some could end up double height. QTableWidget provides appropriate signals for each event such as change of selection, click, double click, etc. . We can add one or more tables in our PyQt application using QTableWidget. text() In this case, the 0 and the 1 in the item call are your columns, in a 0 indexed array. Since the search can return many items, but . Maybe sorting the data myself and then the rowIndex would be the same 2. setItem(. Not sure if there is one and I'm missing it. Dec 13, 2015 · How to get the row number of widget placed in a cell of Qtablewidget when it get clicked? 2 how to get the row number of an item in the qlistwidget using Pyqt5 in python Oct 23, 2012 · Each table widget starts with a Row id as 1. Here, I will assume the headers are on the first row. For example: QItemSelectionModel *selections = this->ui->tableWidget->selectionModel(); QModelIndexList selected = selections->selectedRows(3); qSort(selected); QModelIndex first = selected. If you want to get the complete rows of the selected elements then a possible solution is: Get the rows. data() Feb 14, 2017 · It crashes when I attempt to store data using QtCore. int QTableWidget::rowCount () const. AGo. See also supportedDropActions(). . To do this automatically when a row is clicked, you'll want to use the signal itemClicked. You can use the insertRow () function to insert new rows into the middle of your table as well. Mar 29, 2022 · I have a QTableWidget in my PyQt5 GUI, and what I want to do is row by row, assign specific cell values to my variables. Mar 16, 2015 · If you want to get the values of selected items, you can use selectedItems() API and get the QListWidgetItem list. The only difference is, that You can't execute myTableWidget. void QTableWidget:: cellPressed ( int row, int column) [signal] This signal is emitted whenever a cell in the table is pressed. sibling(index. tableView. Try replacing data = "\n". Hot Network Questions I am using PyQt5. Qt C++ Get data from every cell of a selected row from a QTableView. row1 = [a1. show() app. import sys. From this list you can fetch QListWidgetItem one-by-one and get QListWidgetItem. I can search data from the table, like, if I search for '10', whole data starting with '10' will be displayed. Returns the item for the given row and column if one has been set; otherwise returns nullptr. text() Error: AttributeError: 'NoneType' object has no attribute 'text' Oct 2, 2016 · The expected print was the edited data, but what I get is the data before it was edited. You can use QTableWidget 's itemSelectionChanged or currentCellChanged signal to Dec 13, 2023 · On each row of my table, I have a QPushButton set at a CellWidget like this: Is there any way to get the Row number of table that the QPushButton is in once user press on any of the button? For example, if user click on the QPushButton on the row 2 of the table, it returns a value of 2. setCurrentItem selects only one, you will probably want to provide some mechanism to step through the searches. Oct 7, 2014 · My goal is to have a QTableWidget in which the user can drag/drop rows internally. To show only rows with selected value ( key = "3") Aug 8, 2022 · Hi, I try to make an desktop app that get some values from user and make some calculations and show result. setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); Jun 7, 2016 · # creates a new df from qtables dimensions, # copies qtable (data & headers) to the df and returns the df @staticmethod def write_qtable_to_df(table): col_count = table. connect(self. findItems to get a list of matching QTableWidgetItems, which can then be queried for their co-ordinates. QString text () const. How do you get ROW numbers in QTableView using QStandardItemModel I used below selection model and behavior as. siblingAtColumn(5). It provides an item for use with the QTableWidget class. Apr 3, 2019 · 1. 7, and I have a fully populated QTableView of variable number of rows and set number of columns. currentRow() path = (self. Careful with words, you mean column not record. viewClicked) Sep 11, 2010 · @mikerodent yes, there is an effect. index. It also gives you a lot of flexibility in how the data is displayed/edited. setSortingEnabled(False) 2) pad the number strings with blanks and make all strings in the column have the same length: (' '+numStr)[-4:] 3) after filling the table, turn on sorting: Aug 17, 2018 · See the following figure: The width of the QTableWidget should be adjusted so that it is not smaller than a reasonable minimum and not extend beyond the buttons above it; in particular, the size of the columns 1, 2, and 4 should be adjusted to their contents, and the 3rd column, Aberrations, should be expanded to fill in the gap on the right side. setItem(0, 0, item) The thing is, the new item is created as a new independent object you will then add to your container. When one of the QTableView 's QModelIndex is clicked I want to select an entire row of the same-row-indexes. bool QTableWidget. 'sumCol(self)' to loop through each row, add each item of a column to a list, find the total, and print to QLineEdit. 5 How to copy a row of QtableWidget and insert to the line below it? 3 Nov 21, 2010 · It should get the QModelIndex at cell 2,2 and output its row and its column, which of course should be 2 and 2. 9. May 18, 2021 · Following the docs of QTableWidget, before adding QTableWidgetItems into cells you must declare the size of the QTableWidget (rows and columns). QList<QTableWidgetItem *> list = selectedItems(); Aug 7, 2012 · QTableWidget have a method to search for a row with user data? Something like: //set user data row->setData(0, Qt::UserRole, "ID001"); //find row by user data int rowIndex = table-&gt;findByD The row and column specified is the cell that was clicked. To accomplish this I connect QTableView 's clicked signal to a custom viewClicked() method which receives the clicked QModelIndex automatically: self. table_proj. Suppose a QTableView defined in some MyClass class. When I select one row/cell and click a QPushButton it opens the specific vector/ratser layers in the QGIS. You can use QTableWidgetItem::data() to retrieve the value that you store. int row = item ->row (); void QTableWidget:: setCellWidget (int row, int column, QWidget *widget) Sets the given widget to be displayed in the cell in the given row and column , passing the ownership of the widget to the table. A B C 1 a1 b1 c1 2 a2 b2 c2 3 a3 b3 c3 I want to get the selected row values as a list. QPersistentModelIndex(. Please help me. currentColumn() cell_value = table. The QTableView class is one of the Model/View Classes and is part of Qt's model/view framework. This function was introduced in Qt 4. Dec 15, 2010 · For example, QTableWidget is fine to just show the user some quick information, but if you require more than that, then you should use a model-based approach and thus store the data yourself. Hot Network Questions How to use "given" in expository writing. setModel() of the QTableView to your subclassed model. answered Jul 11, 2014 at 11:40. column(5)). data(index))) IndexError: list index out of range when another row is clicked. value, a2. In order to get the first and last item in the selection range you can simply sort that list. QWidget): def __init__(self, rows, columns): Jun 3, 2013 · Try something like this: def addDataClicked(self): username = self. QTableWidgetItem* item(int row, int column) const. Feb 27, 2019 · I have two tables. The Row id of the Second Widget should not be the same as 1. Feb 11, 2022 · You can call myTableWidget. Used like this: int row = 1; int col = 1; QTableWidgetItem* theItem = theTableWidget->item(row, col); and extract the text using QTableWidgetItem method. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: pow(row, column+1))); tableWidget->setItem(row, column, newItem May 8, 2011 · After watching many threads about getting selected rows numbers, I am really confused. If the selected cells are all in the same row, you could do this ( table refers to the QTableWidget). Example Table and section of code: Table Apr 2, 2020 · I am using PySide2 and have a QTableWidget that is connected to my database. QList<QTableWidgetItem *> items = ui -> table ->findItems ( "search string", Qt::MatchExactly); for (QTableWidgetItem *item : items) {. setModel() is a private method. Returns true if the data and action can be handled by the model; otherwise returns false. I prepared my design from QtDesigner, convert design to code and all I want is just get the value from the table cell. table = QTableView () I need to do this the retrieve the rows selected by the user: indexes = self. The row and column specified is the cell that was double clicked. To create columns: ui->tableWidget->setColumnCount('the number of columns'); before you can insert rows you need to set the total rows: ui->tableWidget->setRowCount('number of rows'); now loop through rows and columns and set the data in each. So tracking table selection should be enough. class Widget(QtWidgets. Jan 29, 2013 · def get_selected_cell_value(): current_row = self. But it may be simpler to use filter. from PyQt5 import QtCore as qtc. note: QTableWidgetItem (const QString &text) The QTableWidgetItem class provides an item for use with the QTableWidget class. table. May 21, 2013 · To add to what Junuxx pointed out. row(),index. tblSession. at vp jf yq nf rv eb fi hm fe