qtableview

pyqt qt4 QTableView how to disable sorting for certain columns?

本小妞迷上赌 提交于 2019-12-01 19:19:04
So I have a QTableView and I only want to let column sorting on column 1 but not column2. Naturally I tried to installEventFilter on QHeaderView or QTableView , but MouseButtonPress event is not being passed unless you installEventFilter on QApplication Now if when eventFilter is called, the target object is always the top level widget although event.pos() is actually relative to the header or tablecell depending on where you click. So we cannot use QHeaderView.rect().contains(event.pos()) to find out if the user clicks on the header because you get false positive when you click on the top

How to change orientation of Qt TableView

北慕城南 提交于 2019-12-01 18:30:01
Hi I am using a QTableView to display data from a sql table using the qsqltablemodel asfollows: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QSqlTableModel(this); model->setTable("staging"); model->select(); model->setHeaderData(0, Qt::Vertical, tr("ID")); model->setHeaderData(1, Qt::Vertical, tr("Region")); model->setHeaderData(2, Qt::Vertical, tr("T1")); model->setHeaderData(3, Qt::Vertical, tr("N1")); model->setHeaderData(4, Qt::Vertical, tr("M1")); ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui

Cannot connect (null)::selectionChanged to QTableView

我怕爱的太早我们不能终老 提交于 2019-12-01 17:57:10
问题 I have the following promoted QTableView: class QRightClickableTableView : public QTableView { Q_OBJECT public: explicit QRightClickableTableView(QWidget *parent = 0): QTableView(parent) {} private slots: void mouseReleaseEvent(QMouseEvent *e) { if(e->button()==Qt::RightButton) emit rightClicked(); else if (e->button()==Qt::LeftButton) emit leftClicked(); } signals: void rightClicked(); void leftClicked(); }; When binding the selectionChanged signal of QRightClickableTableView, but getting an

pyqt qt4 QTableView how to disable sorting for certain columns?

南笙酒味 提交于 2019-12-01 17:30:56
问题 So I have a QTableView and I only want to let column sorting on column 1 but not column2. Naturally I tried to installEventFilter on QHeaderView or QTableView , but MouseButtonPress event is not being passed unless you installEventFilter on QApplication Now if when eventFilter is called, the target object is always the top level widget although event.pos() is actually relative to the header or tablecell depending on where you click. So we cannot use QHeaderView.rect().contains(event.pos()) to

Text styling in QTableView with PySide2

拈花ヽ惹草 提交于 2019-12-01 14:21:18
I have a QTableView populated with a proper model. I would like to change the style of the text based on the context of it: The text, if there is something between parenthesis, just this part of text should change to green color -parenthesis included- (and bold, just if it is not harder). If you can provide a snippet or super simple example, I appreciate it. You have to use a delegate that uses QTextDocument : import random from PySide2 import QtCore, QtGui, QtWidgets words = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris euismod cursus mi sit amet pellentesque. Proin sed

Text styling in QTableView with PySide2

心已入冬 提交于 2019-12-01 13:02:16
问题 I have a QTableView populated with a proper model. I would like to change the style of the text based on the context of it: The text, if there is something between parenthesis, just this part of text should change to green color -parenthesis included- (and bold, just if it is not harder). If you can provide a snippet or super simple example, I appreciate it. 回答1: You have to use a delegate that uses QTextDocument : import random from PySide2 import QtCore, QtGui, QtWidgets words = '''Lorem

Add items to columns in QStandardItemModel

不羁岁月 提交于 2019-12-01 10:51:28
I am currently adding rows to my QTableView as such QStandardItem* itm; QStandardItemModel* model = new QStandardItemModel(this); model->setColumnCount(2); model->appendRow(new QStandardItem("Some Text in Column1"); How do I add items to column 2 dynamically by appending? In the above example column 2 is empty. How do I add item to column 2? Calling appendRow(QStandardItem *) only adds a single item to the first column. You would need to pass in a QList to appendRow() to add items to each column, e.g.: QList<QStandardItem *> items; items.append(new QStandardItem("Column 1 Text")); items.append

A checkbox only column in QTableView

淺唱寂寞╮ 提交于 2019-12-01 09:19:04
I have a table in Sqlite database which I display using QTableview and QSqlQueryModel. The first column needs to have a header which is a checkbox and all the items in the column need to be checkboxes too. I have implemented the first column header as a checkbox and it works perfectly. Since the checkboxes in the column need to be centered, I used a delegate to paint it. I have painted checkboxes using the following code, but they cannot be checked or unchecked. I do not know how to implement that. static QRect CheckBoxRect(const QStyleOptionViewItem &view_item_style_options) {

Paste in the field of QTableView

落爺英雄遲暮 提交于 2019-12-01 08:17:54
问题 I need to implement a function in python which handles the "paste" when "ctrl+v" is pressed. I have a QTableView , i need to copy a field of the table and paste it to another field of the table. I have tried the following code, but the problem is that i don't know how to read the copied item (from the clipboard) in the tableView. (As it already copies the field and i can paste it anywhere else like a notepad). Here is part of the code which I have tried: class Widget(QWidget): def __init__

A checkbox only column in QTableView

情到浓时终转凉″ 提交于 2019-12-01 06:23:49
问题 I have a table in Sqlite database which I display using QTableview and QSqlQueryModel. The first column needs to have a header which is a checkbox and all the items in the column need to be checkboxes too. I have implemented the first column header as a checkbox and it works perfectly. Since the checkboxes in the column need to be centered, I used a delegate to paint it. I have painted checkboxes using the following code, but they cannot be checked or unchecked. I do not know how to implement