qtablewidget

PyQt : Checkbox in QTableWidget

时光怂恿深爱的人放手 提交于 2019-11-29 15:01:50
问题 I use following code to put a checkbox in the 9th column of my QTableWidget chkBoxItem = QtGui.QTableWidgetItem() chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) chkBoxItem.setCheckState(QtCore.Qt.Unchecked) table.setItem(rowNo,9,chkBoxItem) Where table is my QtTableWidget . I need to add the row where the checkbox is clicked to a list.. how on earth do I achieve this? Kind regards, 回答1: One way to do it would be: connect the itemClicked signal of the table to a

pyqt QTablewidget remove scrollbar to show full table

隐身守侯 提交于 2019-11-29 14:50:02
问题 I have a scrollview to which I dynamically add QTableWidgets. However, the QTables themselves also have scrollbars and therefore dont show the full table. Is there a way to disable the scroll bar so that the table always gets shown in full? EDIT: I added self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) as suggested. The scroll bar does disappear, but it still only shows the partial tables (Ican scroll with hovering iverthe table

How validate a cell in QTableWidget?

两盒软妹~` 提交于 2019-11-29 12:23:55
I work eith pyqt4 in python3.4 I want to validate if the text in the cell is a float number when it is introduced. How I do that? You have two options. You can create a QItemDelegate and override the createEditor , setEditorData and setModelData to control the widget they're presented with to edit the data. You can create a QLineEdit with a validator if you'd like, but if they can only enter a number, you should probably just use a QSpinBox or QDoubleSpinBox , which only allow integers and floats. Alternatively, you could let them enter whatever they want and then in the setModelData function

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 do I add a header with data to a QTableWidget in Qt?

亡梦爱人 提交于 2019-11-29 08:02:48
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 appropriate. I'm trying to start off easy and get just the header to display "Last" (as in last name). Here

How can I add a checkbox/radio button to QTableWidget

 ̄綄美尐妖づ 提交于 2019-11-29 00:05:06
问题 How can I add a checkbox/radiobutton/combobox to a QTableWidget or a QListWidget? 回答1: For a checkbox using the item's setCheckState method should do what you need both for list and table widgets. See if code below would work for you: List widget: QListWidgetItem *item0 = new QListWidgetItem(tr("First"), listWidget); QListWidgetItem *item1 = new QListWidgetItem(tr("Second"), listWidget); item0->setCheckState(Qt::Unchecked); item1->setCheckState(Qt::Checked); Table widget: QTableWidgetItem

Set default alignment for cells in QTableWidget

旧时模样 提交于 2019-11-28 09:05:35
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? 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 QTableWidgetItem(); protoitem->setTextAlignment(Qt::AlignLeft); etc... Then each time you want to create a new

Python Qt: How to catch “return” in qtablewidget

不羁的心 提交于 2019-11-28 06:30:48
问题 I would like to catch the return key in a qtablewidget to do something with the currently marked cell. That is: I want the user to press the "return/enter" key on his keyboard when any cell is highligted. Pressing that button should issue a new method. For example show a messagebox with the content of that cell. How do I connect the event of pressing the return key to a method? Since I am new to python I have no idea how to do that and would be grateful for any advice. 回答1: Your question is a

Adding widgets to qtablewidget pyqt

别等时光非礼了梦想. 提交于 2019-11-28 03:28:21
问题 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) 回答1: You have a couple of questions