qtableview

Formatting data in a QTableView

冷暖自知 提交于 2019-12-08 19:39:27
I'm using a custom delegate to display QDoubleSpinBoxes in a QTableView. Those spinboxes display their contents with two decimals. My problem is that I would like the QTableView to also display those numbers with two decimals while they are not being edited (at which point they are not in a QDoubleSpinBox). Or, rather, I would like to be able to specifiy a format for the QTableView's contents. I tried to subclass QStyledItemDelegate to override displayText, but for a strange reason it crashes. It works correctly if I simply subclass QItemDelegate. I'm using Qt 4.6.3, on Windows. I'm not really

QTableView disable sorting for some columns

随声附和 提交于 2019-12-08 12:35:18
问题 I am using QtableView(qt5.9) with 10 columns and want to disable sorting for 2nd and 3rd (only some) columns when the user clicks on the header of these columns. I use setsortingenabled flag to make my QtableView allow sorting Is there any signal which I should listen to on clicking of header and then call some appropraite method or deny sorting. 回答1: You can use the header signal sortIndicatorChanged to restore the current sort indicator. Example: connect(m_poTableView->header(),

what is QAbstractView in QT (this statement)?

﹥>﹥吖頭↗ 提交于 2019-12-08 11:54:29
问题 I am attempting to disable editing in my table view. I came across this thread which states that you could do the following tableView.setEditTriggers(QAbstractView::NoEditTriggers); My question is what is the QAbstractView here ? 回答1: that seems to be a typo and should read QAbstractItemView, which is the baseclass of QTableView where the EditTriggers enum (which NoEdittriggers is an element of) is declared. 来源: https://stackoverflow.com/questions/20023435/what-is-qabstractview-in-qt-this

QFileDialog as editor for TableView: how to get result?

微笑、不失礼 提交于 2019-12-08 08:04:14
问题 I'm using a QFileDialog as the editor for some columns in a QTableView . This basically works (modulo some focus issues, see here): class DirectorySelectionDelegate(QStyledItemDelegate): def createEditor(self, parent, option, index): editor = QFileDialog(parent) editor.setFileMode(QFileDialog.Directory) editor.setModal(True) return editor def setEditorData(self, editor, index): val = index.model().data(index, Qt.DisplayRole) fs = val.rsplit(os.path.sep, 1) if len(fs) == 2: bdir, vdir = fs

how can i achieve to update multiple rows in a qtableview

安稳与你 提交于 2019-12-08 07:28:52
问题 I have a customized qtablemodel and a qtableview. I would like to add a feature that the user can select multiple rows and by changing one of the values within this rows. He would actually change this value in all rows. e.g. the user could change the name of all persons in the table to alice when he selected the whole table. Can you help me to achieve this? I do not understand how i can trigger the setData of the model a multiple times for different rows. Or can you tell me which signal the

Formatting data in a QTableView

泪湿孤枕 提交于 2019-12-08 06:58:27
问题 I'm using a custom delegate to display QDoubleSpinBoxes in a QTableView. Those spinboxes display their contents with two decimals. My problem is that I would like the QTableView to also display those numbers with two decimals while they are not being edited (at which point they are not in a QDoubleSpinBox). Or, rather, I would like to be able to specifiy a format for the QTableView's contents. I tried to subclass QStyledItemDelegate to override displayText, but for a strange reason it crashes

how do i get a checkbox item from a QTableView and QStandardItemModel alone?

我们两清 提交于 2019-12-08 06:11:15
问题 Seems using model.setData(index, Qt::Checked,Qt::CheckStateRole) is not enough to get the checkbox working right. Any suggestions? 回答1: I believe you would need to subclass QStandardItemModel; override flags method and return Qt::ItemIsUserCheckable along with other flags for the column with check boxes. Below is an example: class TableModel : public QStandardItemModel { public: TableModel(); virtual Qt::ItemFlags flags ( const QModelIndex & index ) const; }; TableModel::TableModel() { //???

PyQt: How to insert text at the cursor in QTableView

我是研究僧i 提交于 2019-12-08 04:02:43
问题 I have a QTableView as below. I'd like to press the Test button and insert an "a" at the cursor - for example in the middle of "11" at (row,column) = (2,2). That is, the user double-clicks cell (2,2) and places the cursor in the middle of "11", and presses Test. Desired result: "1a1". Is this doable? If yes, how? Thanks very much. # coding: utf-8 import sys from PyQt4 import QtGui, QtCore from PyQt4.QtCore import * from PyQt4.QtGui import * MY_ARRAY = [['00', '01', '02'], ['10', '11', '12'],

how to connect two QTableview Widgets?

风格不统一 提交于 2019-12-08 03:24:08
问题 import sys from PyQt5 import QtCore as qtc from PyQt5 import QtWidgets as qtw from PyQt5 import QtGui as qtg import os.path import pandas as pd class a(qtw.QStyledItemDelegate): def createEditor(self, parent, option, index): line_edit = qtw.QLineEdit(parent) line_edit.setMaxLength(3) return line_edit class ColorDelegate(qtw.QStyledItemDelegate): def initStyleOption(self, option, index): super().initStyleOption(option, index) if option.text.strip(): # condition option.backgroundBrush = qtg

how to connect two QTableview Widgets?

半腔热情 提交于 2019-12-07 18:57:20
import sys from PyQt5 import QtCore as qtc from PyQt5 import QtWidgets as qtw from PyQt5 import QtGui as qtg import os.path import pandas as pd class a(qtw.QStyledItemDelegate): def createEditor(self, parent, option, index): line_edit = qtw.QLineEdit(parent) line_edit.setMaxLength(3) return line_edit class ColorDelegate(qtw.QStyledItemDelegate): def initStyleOption(self, option, index): super().initStyleOption(option, index) if option.text.strip(): # condition option.backgroundBrush = qtg.QColor("red") class MainWindow(qtw.QMainWindow): def __init__(self): super().__init__() ##Main framwork