qtablewidget

How to show the row where QPushButton is clicked in QTableWidget

混江龙づ霸主 提交于 2019-12-04 04:55:21
问题 I would like to delete row where QPushButton is clicked how it is possible to I think it is reasonable to use slots but how to do it don't know , if you have any ideas how to get a row of selected button please share, thanks. It is my table It is a code where i add rows to my QTableWidget MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); for(int i = 0; i<20;i++) ui->tableWidget->insertRow(ui->tableWidget->rowCount()); QVector<QString

Set widget background color

*爱你&永不变心* 提交于 2019-12-04 03:34:18
I use QCheckBox in QTableWidgetCell QWidget *widget = new QWidget(); QCheckBox *checkBox = new QCheckBox(); QHBoxLayout *layout = new QHBoxLayout(widget); layout->addWidget(checkBox); layout->setAlignment(Qt::AlignCenter); layout->setContentsMargins(0, 0, 0, 0); widget->setLayout(layout); table->setCellWidget(0, 0, widget); How can I change cell background? The code: widget->setStyleSheet("background-color: red"); works fine but you need to set the style for every container widget you add to your table: So in order to see the change you need the following code: QWidget *widget = new QWidget();

Sorting in pyqt tablewidget

六月ゝ 毕业季﹏ 提交于 2019-12-04 02:00:04
问题 How can I sort a coloumn in pyqt by the highest number? Currently I have setSortingEnabled(True) and that only sorts it by the most numbers (ex. 1,1,1,1,2,2,2,3,3) i want to do it by the highest number for example (ex. 58,25,15,10). Thanks! Data Update: def setmydata(self): for n, key in enumerate(self.data): for m, item in enumerate(self.data[key]): newitem = QtGui.QTableWidgetItem(item) self.setItem(m, n, newitem) Whole code: import sys from PyQt4.QtGui import QTableWidget from PyQt4 import

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

Turn off PyQt Event Loop While Editing Table

南楼画角 提交于 2019-12-03 14:40:38
I'm developing a GUI with PyQt. The GUI has a qListWidget, a qTableWidget, and a plot implemented with Mayavi. The list refers to shapes that are plotted (cylinders and cones for example). When a shape is selected in the list, I want the shape's properties to be loaded into the table (from a dictionary variable) and the shape to be highlighted in the plot. I've got the Mayavi plotting working fine. Also, if the table is edited, I need the shape to be re-plotted, to reflect the new property value (like for a cylinder, if the radius is changed). So, when a list item is selected -> update the

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

Selecting QComboBox in QTableWidget

一世执手 提交于 2019-12-03 10:33:59
One cell in each row of a QTableWidget contains a combobox for (each row in table ... ) { QComboBox* combo = new QComboBox(); table->setCellWidget(row,col,combo); combo->setCurrentIndex(node.type()); connect(combo, SIGNAL(currentIndexChanged(int)),this, SLOT(changed(int))); .... } In the handler function ::changed(int index) I have QComboBox* combo=(QComboBox*)table->cellWidget(_row,_col); combo->currentIndex() To get back a copy of the combobox and get the new selection. But I can't get the row/col. None of the table cellXXXX signals is emitted when an embedded item is selected or changed and

Python PyQt - QTableWidget, JSON, and emitSignal causing blank cells

不想你离开。 提交于 2019-12-03 08:55:12
I am using PyQt for a simple application that reads from a log file with JSON formatted strings, and outputs them nicely in a table. Everything is working as expected except when I try to emit a signal from a 'load' function. This signal is picked up by the main window, in a slot designed to resort the table with new information. Without the signal emitted, the table populates fully and properly: By uncommenting the self.emit so that the signal IS emitted, the table ends up being incomplete: As you can see in the first image, the table is NOT sorted, but all fields are populated. In the second

add custom widget to QTableWidget cell

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have custom widget made with qt designer and i want to add it to QTableWidget cell. But it doesn't work. Here is the code : int nRows = 10 ; for ( int row = 0 ; row < nRows ; row ++;) { QTableWidgetItem * item = new QTableWidgetItem (); CustomWdg * wdg = new CustomWdg ( ); mTableWdg -> insertRow ( row ); mTableWdg -> setItem ( row , 0 , item ); mTableWdg -> setCellWidget ( row , 0 , wdg ); } 回答1: If you want to add custom widget into table cell you can use QItemDelegate. Create your own Delegate class and inherit it from

How to delete all rows from QTableWidget

橙三吉。 提交于 2019-12-03 06:32:40
问题 I am trying to delete all rows from a QTableWidget . Here is what I tried. for ( int i = 0; i < mTestTable->rowCount(); ++i ) { mTestTable->removeRow(i); } I had two rows in my table. But this just deleted a single row. A reason could be that I did not create the the table with a fixed table size. The Qt Documentation for rowCount() says, This property holds the number of rows in the table. By default, for a table constructed without row and column counts, this property contains a value of 0.