qtablewidget

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

How do I add a header with data to a QTableWidget in Qt?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 01:57:25
问题 I'm still learning Qt and I am indebted to the SO community for providing me with great, very timely answers to my Qt questions. Thank you. I'm quite confused on the idea of adding a header to a QTableWidget . What I'd like to do is have a table that contains information about team members. Each row for a member should contain his first and last name, each in its own cell, an email address in one cell, and office in the other cell. I'd to have a header above these columns to name them as

Qt - Cannot put an image in a table

那年仲夏 提交于 2019-11-28 01:42:14
问题 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

Adding widgets to qtablewidget pyqt

﹥>﹥吖頭↗ 提交于 2019-11-28 00:57:59
Is there anyway to add like a button in qtablewidget? But the date within the cell would stil have to be displaying, for example if an user double clicked a cell, could i send a signal like a button? Thanks! edititem(): def editItem(self,clicked): if clicked.row() == 0: #go to tab1 if clicked.row() == 1: #go to tab1 if clicked.row() == 2: #go to tab1 if clicked.row() == 3: #go to tab1 table trigger: self.table1.itemDoubleClicked.connect(self.editItem) You have a couple of questions rolled into one...short answer, yes, you can add a button to a QTableWidget - you can add any widget to the table

Python PyQt: QTableWidget - get cell value based on header string and selected row

人走茶凉 提交于 2019-11-27 15:22:33
For example, I have a PyQt QTableWidget which has 3 columns and 2 rows. The column headers are labeled A, B, and C. A B C 1 2 3 4 5 6 This is the excerpt from my current source: class myform(QtGui.QMainWindow): def __init__(self, parent=None): super(myform, self).__init__(parent) self.ui = Ui_mygui() self.ui.setupUi(self) self.ui.mytablewidget.cellClicked.connect(self.cell_was_clicked) @QtCore.pyqtSlot() # prevents executing following function twice def cell_was_clicked(self): row = self.ui.mytablewidget.currentItem().row() print "row=",row col = self.ui.mytablewidget.currentItem().column()

writing a QTableWidget to a .csv or .xls

无人久伴 提交于 2019-11-27 09:20:56
Is it possible to write the contents of a QTableWidget to a csv? I found a question about writing to an .xls using xlwt, but can't seem to get it to work using my code. def saveFile(self): filename = unicode(QtGui.QFileDialog.getSaveFileName(self, 'Save File', '', ".xls(*.xls)")) wbk = xlwt.Workbook() self.sheet = wbk.add_sheet("sheet") self.write() wbk.save(filename) def write(self): for col in range (self.coordinates.columnCount()): for row in range(self.coordinates.rowCount()): text=str(self.coordinates.item(row,col).text()) self.sheet.write(row,col,text) I get the following error: File "C:

Resize column width to fit into the QTableWidget pyqt

允我心安 提交于 2019-11-27 06:05:05
问题 I've googled around but I'm not able to find a solution to my problem. I have a QTableWidget with 2 columns and what I'm trying to do is to make them visible to the whole widget without the horizontal scrollbar to appear. With a picture it should be all clear: I have used Qt Designer to create the UI and some code to fill all the widgets and other stuff. So, first I resized th2 2 columns to the content with: self.statTable.resizeColumnToContents(0) self.statTable.resizeColumnToContents(1) and

How to make a column in QTableWidget read only?

拈花ヽ惹草 提交于 2019-11-27 03:31:32
I would like to have one column in QTableWidget NOT editable. In forums I have read a lot about some flags but could not manage to implement. Insert into the QTableWidget following kind of items: QTableWidgetItem *item = new QTableWidgetItem(); item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); Works fine! EDIT: QTableWidgetItem *item = new QTableWidgetItem(); item->setFlags(item->flags() ^ Qt::ItemIsEditable); This is a better solution. Thanks to @priomsrb. user2923436 The result of using XOR depends on what the current state is. I'd suggest using item->setFlags(item->flags() & ~Qt:

Set default alignment for cells in QTableWidget

与世无争的帅哥 提交于 2019-11-27 02:13:44
问题 I know you can set the alignment for each item using: TableWidget->item(0,0)->setTextAlignment(Qt::AlignLeft); However I would like to set a default alignment for all the cells in order to do not have to set it every time I create a new item. Is it possible? 回答1: Yes it is possible. But you need to understand you are not modifying a property of the table widget, but a property of the table widget item. First create your own item, and set it up as you want QTableWidgetItem * protoitem = new

PyQT QTableWidget extremely slow

随声附和 提交于 2019-11-26 14:56:45
问题 this is the code I use to fill a table drawn in QT Designer. Designed to be universal for any table, it works fine, but... When I try to show a datasat containing 18 columns and ~12000 rows, it just freezes for 30 seconds or more. So, what I am doing wrong and is there way to speed up, keeping the code still suitable for any table? That's my code: ...blablabla... self.connect(self, SIGNAL("set"), self.real_set) ...blablabla... def set_table(self, table, data): self.emit(SIGNAL('set'), table,