qtableview

Pandas df in editable QTableView: remove check boxes

主宰稳场 提交于 2019-12-04 04:00:57
问题 I have a pandas dataframe that I would like to present in a QtableView and make it editable. I have create the below model, but for some reason the output has checkboxes in every field. How can I get rid of them? The outout looks like this: And this this is the model that is used to make the pandas dataframe shown in a qtavleview and make it editable (I'm using PySide) class PandasModelEditable(QtCore.QAbstractTableModel): def __init__(self, data, parent=None): QtCore.QAbstractTableModel._

how to retrieve the selected row of a QTableView?

怎甘沉沦 提交于 2019-12-04 03:24:16
I'm using a QTableView object types. This object contains several online and I use this model: class PaletteTableModel(QtCore.QAbstractTableModel): def __init__(self,colors = [[]],headers =[],parent=None): QtCore.QAbstractTableModel.__init__(self, parent) self.__colors=colors self._headers=headers def rowCount(self,parent): return len(self.__colors) def columnCount(self,parent): return 6 def headerData(self,section,orientation,role): if role==QtCore.Qt.DisplayRole: if orientation==QtCore.Qt.Horizontal: return self._headers[section] else: return QtCore.QString("Credit %1").arg(section+1) def

QTableView: How can I get the data when user click on a particular cell using mouse

坚强是说给别人听的谎言 提交于 2019-12-04 03:06:37
Actually I am new to Qt and unable to match up QMouseEvent with QTableview please help in solving this issue. vahancho Here is an example of how you can get a table cell's text when clicking on it. Suppose a QTableView defined in some MyClass class. You need to connect the clicked signal to your own MyClass::onTableClicked() slot, as shown below: connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &))); Slot implementation: void MyClass::onTableClicked(const QModelIndex &index) { if (index.isValid()) { QString cellText = index.data().toString();

Qt Delete selected row in QTableView

时光总嘲笑我的痴心妄想 提交于 2019-12-04 01:09:51
问题 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? 回答1: 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.

Read and write to a file from a QTableView

孤街浪徒 提交于 2019-12-03 22:17:20
How can I read and write to a text file date enter to a QTableView? This is what I have but I would like to save the data when it is added to the table and of course be able to read it back when the application is reopened. Is there any tutorial I can refer to? MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QStandardItemModel(); model->setRowCount(0); ui->tableView->setModel(model); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QStandardItem *userName = new QStandardItem(ui->lineEdit

Qt: start editing of cell after one click

﹥>﹥吖頭↗ 提交于 2019-12-03 15:28:12
问题 By default the cell in QTableView starts being edited after double click. How to change this behavior. I need it to start editing after one click. I have set combo-box delegate to the cell. When clicking the cell it only selects it. When double clicking on the cell the QComboBox editor is activated but not expanded. I want it to expand after just one click as if I added QComboBox by setCellWidget function of QTableWidget . I need the same effect by using model-view-delegate. 回答1: Edit after

Change QSortFilterProxyModel behaviour for multiple column filtering

若如初见. 提交于 2019-12-03 15:18:05
We have a QSortFilterProxyModel installed on a QTableView and two (or more) QLineEdit for filtering the view (based on the text of these QLineEdit s) In our view we have a slot that tells us the string of lineedits and the current column that we want. Something like this : void onTextChange(int index, QString ntext) { filter.setFilterKeyColumn(index); filter.setFilterRegExp(QRegExp(ntext, Qt::CaseInsensitive)); } On the first column we have names in the second we have year of birthday. Now we enter a year for column 2 (for example 1985). Until now filtering is ok but when we switch to the

How can I get right-click context menus for clicks in QTableView header?

我只是一个虾纸丫 提交于 2019-12-03 09:53:54
问题 The sample code below (heavily influenced from here) has a right-click context menu that will appear as the user clicks the cells in the table. Is it possible to have a different right-click context menu for right-clicks in the header of the table? If so, how can I change the code to incorporate this? import re import operator import os import sys from PyQt4.QtCore import * from PyQt4.QtGui import * def main(): app = QApplication(sys.argv) w = MyWindow() w.show() sys.exit(app.exec_()) class

PySide + QTableView example

痞子三分冷 提交于 2019-12-03 07:58:37
问题 Can anyone point me to a simple example of QTableView in PySide? I found the QTableView docs but unfortunately they don't give an example, and I'm very new to PySide, so I don't even know how to start. (I am very familiar with the JTable in Java Swing, so I know how to use table models.) 回答1: Found one: http://www.daniweb.com/software-development/python/code/447834/applying-pysides-qabstracttablemodel ''' ps_QAbstractTableModel_solvents.py use PySide's QTableView and QAbstractTableModel for

How to create filters for QTableView in PyQt

大兔子大兔子 提交于 2019-12-03 02:27:36
问题 I am using QTableView to display data retrieved from QtSql.QSqlQuery I want to know how can i create filters for it like in excel. In the above image i need to get the filters for All heders (Sh_Code,SH_Seq,Stage) The filters will have unique values in of that column on which we can filter. Required result I need the Table view header with a dropbox listing all unique values in that column just like in excel below. No need of Top,Standard filter... as shown in image. Need only "All" and the