qtablewidgetitem

How to change Qtablewidget's specific cells background color in pyqt

流过昼夜 提交于 2019-12-03 20:03:25
问题 I am new in pyqt4 and I can't figure out how to do this. I have a QtableWidget with data in it. I want to change some background color of the tableWidget's cells. I tried self.tableWidget.item(3, 5).setBackground(QtGui.QColor(100,100,150)) and it returns this error: AttributeError: 'NoneType' object has no attribute 'setBackground' What should I do? 回答1: You must first create an item in that place in the table, before you can set its background color. self.tableWidget.setItem(3, 5, QtGui

Qt - How to associate data with QTableWidgetItem?

好久不见. 提交于 2019-12-03 14:35:33
I want to associate additional data with each QTableWidgetItem inserted into the table, in order to use that data in future, when it is being clicked on a table item. But that data should not be visible. How can I do that? richardwb You can use QTableWidgetItem::setData() like so: setData(Qt::UserRole, myData); // set Where myData is a supported QVariant type. You can use QTableWidgetItem::data() to retrieve the value that you store. 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.", you

How to edit column formula so it can be calculated automatically?

断了今生、忘了曾经 提交于 2019-12-01 01:42:31
I'm making a project using python where it can behave similar to excel, for example when I input some numbers in my cell, it will be automatically calculated in another cell with a defined algorithm. I have tried implementing some ideas but I get stuck. I can only do simple calculations like adittion and multiplication. I have a problem when I try to edit the code to allow it to do any form of complex calculation. ... def print_it(self,no): if no.column()==2: return try: add = 10 for column in range(0,2): try: add*=int(self.table.item(no.row(),column).text()) except: pass self.table.setItem(no

How to edit column formula so it can be calculated automatically?

我的未来我决定 提交于 2019-11-30 21:04:13
问题 I'm making a project using python where it can behave similar to excel, for example when I input some numbers in my cell, it will be automatically calculated in another cell with a defined algorithm. I have tried implementing some ideas but I get stuck. I can only do simple calculations like adittion and multiplication. I have a problem when I try to edit the code to allow it to do any form of complex calculation. ... def print_it(self,no): if no.column()==2: return try: add = 10 for column

How do I assign a border to a specific QTableWidgetItem or a row in a QTableWidget?

一笑奈何 提交于 2019-11-29 08:39:06
I am trying to make certain cells in my QTableWidget have different colored borders based on the information contained in an item(cell). I do not want to select those cells and use the selection-color styles because different cells need to be selected/highlighted. for ex. I have a table with 3 columns and 3 rows. All the cells have simple text in each of them. [] [Name] [Value] [Units] [1] [one] [1] [cm] [2] [two] [2] [in] [3] [three][3] [m] The 1st row is selected by the user and is highlighted, a process in the background updates the values in the table and updates the value in the 3rd row

Qt - Cannot put an image in a table

不问归期 提交于 2019-11-29 08:24:47
Why with the following code I just get an empty table widget? QString imgPath = "C:\\path\\to\\image.jpg"; QImage *img = new QImage(imgPath); QTableWidget *thumbnailsWidget = new QTableWidget; QTableWidgetItem *thumbnail = new QTableWidgetItem; thumbnail->setData(Qt::DecorationRole, QPixmap::fromImage(*img)); thumbnailsWidget->setColumnCount(5); thumbnailsWidget->setRowCount(3); thumbnailsWidget->setItem(0, 0, thumbnail); setCentralWidget(thumbnailsWidget); How can I put an image into a QTableWidgetItem? Thank you. P.S.: I noticed that the table is not really empty. Clicking on the different

how to add a right click menu to each cell of QTableView in PyQt

爷,独闯天下 提交于 2019-11-28 19:43:33
I want to add a right click menu to delete, rename or open image in each of cell of QTAbleView in the rigt click menu, I have tried and found everyone is trying to add menu to a header in tableview, i tried below but that seems not working in the code below.. class GalleryUi(QtGui.QTableView): """ Class contains the methods that forms the UI of Image galery """ def __init__(self, imagesPathLst=None, parent=None): super(GalleryUi, self).__init__(parent) self.__sw = QtGui.QDesktopWidget().screenGeometry(self).width() self.__sh = QtGui.QDesktopWidget().screenGeometry(self).height() self._

QTableWidget Integer

青春壹個敷衍的年華 提交于 2019-11-28 11:40:47
I am trying to insert and display integers in my QTableWidget. They don't display. It works if I convert everything to strings, but then I can't sort columns numerically--only lexically (1, 10, 100, etc.). This is using PyQt. I've tried some of the suggested solutions, using QTableWidgetItem.setData(someRole,intValue), bu then nothing at all displays. I've tried, Qt.UserRole, DisplayRole and Edit Role. (I don't understand why these Roles are needed to display integers, but have just followed the examples). My specific code is: item = QTableWidgetItem() item.setData = (Qt.DisplayRole,intValue)

Qt - Centering a checkbox in a QTable

女生的网名这么多〃 提交于 2019-11-28 08:05:10
问题 In QtCreater I added a table to my project. in my code I am generating some data to output into the table. I want to add a QCheckbox into each row to allow the row to be selected. All the content of the table is aligned left, how do I make only these checkboxes in the first column of every row align to the center? I'm adding the QCheckbox using: ui->data_table->setCellWidget(rowCount,0, new QCheckBox); 回答1: I usually use a layout and a container widget for this. It is an ugly solution, but it

How do I assign a border to a specific QTableWidgetItem or a row in a QTableWidget?

[亡魂溺海] 提交于 2019-11-28 02:06:54
问题 I am trying to make certain cells in my QTableWidget have different colored borders based on the information contained in an item(cell). I do not want to select those cells and use the selection-color styles because different cells need to be selected/highlighted. for ex. I have a table with 3 columns and 3 rows. All the cells have simple text in each of them. [] [Name] [Value] [Units] [1] [one] [1] [cm] [2] [two] [2] [in] [3] [three][3] [m] The 1st row is selected by the user and is