qtableview

How to interact with checkbox actions ? (QTableView with QStandardItemModel)

随声附和 提交于 2019-12-01 05:46:19
问题 I'm using QTableView and QStandardItemModel to show some data. For each row, there is a column which has a check Box, this check box is inserted by setItem, the code is as follows: int rowNum; QStandardItemModel *tableModel; QStandardItem* __tmpItem = new QStandardItem(); __tmpItem->setCheckable(true); __tmpItem->setCheckState(Qt::Unchecked); tableModel->setItem(rowNum,0,__tmpItem); Now I want to interact with the check box. If a check box changes its state by user (from checked to unchecked

Qt Delete selected row in QTableView

给你一囗甜甜゛ 提交于 2019-12-01 04:18:40
I want to delete a selected row from the table when I click on the delete button. But I can't find anything regarding deleting rows in the Qt documentation. Any ideas? You can use the bool QAbstractItemModel::removeRow(int row, const QModelIndex & parent = QModelIndex()) functionality for this. Here you can find an example for all this. Also, here is an inline quote from that documentation: removeRows() Used to remove rows and the items of data they contain from all types of model. Implementations must call beginRemoveRows() before inserting new columns into any underlying data structures, and

Connecting QTableView selectionChanged signal produces segfault with PyQt

与世无争的帅哥 提交于 2019-12-01 03:59:46
I have a QTableView in a PyQt application, and I want to keep track of when the selection changes. I've tried connecting the signal to a slot as follows (using the advice on this page : self.view.selectionModel().selectionChanged.connect(self.selChanged) where the slot it is connected to is defined as: def selChanged(self, selected, deselected): print "Sel changed" However, whenever I load the QMainWindow on which the QTableView resides, I get an immediate segmentation fault. Am I doing something silly here? eric I was having a similar problem and the fix was here: PySide: Segfault(?) when

How to display content of multiple QSqlTableModels in one QTableView?

半城伤御伤魂 提交于 2019-12-01 01:15:50
I have a MySql table, let's call it x : CREATE TABLE x ( Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, A int unsigned NOT NULL, B int, FOREIGN KEY (A) REFERENCES y(Id) ); And then I have another table, let's call it y : CREATE TABLE y ( Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, First varchar(255), Last varchar(255) ); I want to display table x in one QTableView and in place of column A from table x I want to display columns First and Last from table y from row whose Id is equal to A from table x . Do you have any ideas? Let me know if my explanation is not clear enough. You

checkbox and itemdelegate in a tableview

霸气de小男生 提交于 2019-11-30 15:14:09
I'm doing an implementation of a CheckBox that inherits from QitemDelegate, to put it into a QTableView. the problem is that I get when inserted flush left and I need it centered. As I understand the method that is responsible for the Paint. I have it written as follows: void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { bool checkValue; QStyleOptionButton BtnStyle; BtnStyle.state = QStyle::State_Enabled; if(index.model()->data(index, Qt::DisplayRole).toBool() == true) { BtnStyle.state |= QStyle::State_On; checkValue = true;

Qt hide column in QTableView

。_饼干妹妹 提交于 2019-11-30 13:54:50
问题 I want to hide the ID column in the QtableView and i can't do that on my implementation. Can anyone help me? void MainWindow::on_actionClear_Search_triggered() { model = new QStandardItemModel(cars.size(),6,this); //create header createHeader(model); //set data to the table view populate(cars); ui->tableView->setColumnHidden(6,true); ui->tableView->setModel(model); } void MainWindow::createHeader(QStandardItemModel *model){ model->setHorizontalHeaderItem(0,new QStandardItem("Car")); model-

Selected Rows in QTableView, copy to QClipboard

心已入冬 提交于 2019-11-30 12:04:38
问题 I have a SQLite-Database and I did it into a QSqlTableModel . To show the Database, I put that Model into a QTableView . Now I want to create a Method where the selected Rows (or the whole Line) will be copied into the QClipboard . After that I want to insert it into my OpenOffice.Calc-Document. But I have no Idea what to do with the Selected SIGNAL and the QModelIndex and how to put this into the Clipboard. 回答1: To actually capture the selection you use the item view's selection model to get

How to Copy - Paste Multiple Items form QTableView created by QStandardItemModel to a text/excel file?

你说的曾经没有我的故事 提交于 2019-11-30 09:44:38
问题 How can I copy and paste multiple items/values of a QTableView to a text/ excel file? My Code: tab_table_view = QtGui.QWidget() self.Tab.insertTab(0, tab_table_view, self.File_Name) self.tableView = QtGui.QTableView(tab_table_view) self.tableView.setGeometry(QtCore.QRect(0, 0, 721, 571)) self.model = QtGui.QStandardItemModel(self) self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection This line self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection helps with

Get data from every cell from a QTableView

微笑、不失礼 提交于 2019-11-29 23:40:48
问题 I need the values from a QtableView , but I do not know how to do that without a signal emitted from the table. The table takes its values from a txt-file. From the table, I want to work with the values, but without working in the table. The table is just a buffer. So how can I "take" all the values from the table, just pressing a QPushButton , without any signal from the table itself? 回答1: The QTableView just displays the data contained in its model. You have to work with this model to

Qt Using Custom QItemDelegate for QTableView

我怕爱的太早我们不能终老 提交于 2019-11-29 21:57:34
I followed the Spin Box Delegate tutorial, which Qt provides, to try to implement my own QItemDelegate . It would be used to specify a QComboBox to represent data in a QTableView cell but it is not working. My biggest problem is that I don't know when my QItemDelegate is going to be utilized. when itemModel->setData() is used or when itemModel->setItem() . I would suspect setItem() because I reimplemented a QItemDelegate (emphasis on the "Item") but the tutorial uses setData() and it works fine. I know that if the specified QItemDelegate does not work it uses the default one but how do I now