qtableview

QSQLTableModel inheritor and QTableView

走远了吗. 提交于 2019-12-11 08:14:22
问题 I wrote QSQLTableModel inheritor for working with qml and it's work well. I need use it with QTableView too, data shows, but I cannot modify it - when I edit everything is ok, but all changes drop when I get out from field (I know about editStrategy, but the problem occurs earlier). I suppose that something wrong with virtual function, but I cant undestant what. If i create QSqlTableModel with the same parameters, everything is ok. Somebody have any idea how can i fix this? My code: h: class

PySide2 QListView QTableView sync problem

▼魔方 西西 提交于 2019-12-11 07:45:13
问题 It is python/PySide2 interface related problem, as much as I tried, I couldn't make it sync (QListView and QTableView). I will try to simplify it, instead of explaining the whole complicated thing which is much bigger with full of forms stuff in QT... Just imagine to have a data structure (I guess, model) like the following: dict_of_dicts={ 'dict1':{'k1':'v1', 'k2':'v2', 'k3':'v3'}, 'dict2':{'k4':'v4'}, 'dict3':{'k5':'v5', 'k6':'v6', 'k7':'v7'}, } I would like to have a form (or dialog), with

How to make QTableView to enter the editing mode only on double-click

只愿长相守 提交于 2019-12-11 06:51:40
问题 Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it. Another way to edit the item is to select it and press a keyboard key. How to disable this second way of entering the item's editing mode? Here is the image showing the QTableView with the item selected: As soon as the user presses the keyboard key the selected item is already in the edit mode: This default QTableView behavior makes it impossible to define

PyQt5 column sorting not working when using custom HeaderView

旧街凉风 提交于 2019-12-11 06:01:40
问题 I'm trying to create a TableView with sorting functionality. If I set the TableView obj my custom HeaderView , clicking on the header won't sort, even though my custom HeaderView re-implements nothing. If I use instead the TableView 's header ( hh=tv.horizontalHeader() ) it sorts. What am I doing wrong? Code below: import sys import operator from PyQt5 import QtWidgets from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant class TableModel(QAbstractTableModel): def __init__(self, parent,

QTableView: sort by header index -1

扶醉桌前 提交于 2019-12-11 04:19:12
问题 I am using PyQt4 and have a QTableView with a 2 columns data. There is an extra column for an index (it comes from the headerData function of the source model). For sorting when clicking on the header buttons I wrap my model with a proxy class. That's working fine, but I also want to sort by the first column by clicking on the left-top corner button (column number: "-1" I would say) : As requested, here is a minimal example: from PyQt4 import QtCore, QtGui import random, sys class MyModel

Digits after the decimal QTableView delegate

浪尽此生 提交于 2019-12-11 04:07:36
问题 I need a specified number of digits after the decimal point for the items of QTableView, so I wrote a simple delegate. class TableItemDelegate : public QStyledItemDelegate { Q_OBJECT public: TableItemDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} QString displayText(const QVariant & value, const QLocale & locale) { QString str = QString::number(value.toDouble(), 'f', 8); return str; } }; But it doesn`t work, constructor called, but not the displayText() function.

QTableView - Limit number of selected items?

♀尐吖头ヾ 提交于 2019-12-11 03:21:39
问题 The question is in the title. There is no function QTableView::set_Max_Number_SelectedItems( int ). When the number of selected items is 2, I want to disable selection of item. Thanks 回答1: You can disable selection with this: connect(ui->tableView->selectionModel(),&QItemSelectionModel::selectionChanged,[=]() {//with lambda if(ui->tableView->selectionModel()->selectedIndexes().size() > 1) ui->tableView->setSelectionMode(QAbstractItemView::NoSelection); }); I used here C++11 ( CONFIG += c++11

Qt::BackgroundRole seems to be ignored

不想你离开。 提交于 2019-12-10 19:10:16
问题 I'm using a custom table model derived from QAbstractTableModel . I've overwritter headerData() and I can change the font color for individual row-headers (or column-header, but I'm all about rows here) by returning the color on Qt::ForegroundRole if(role == Qt::ForegroundRole) return Qt::green; But if I go for Qt::BackgroundRole to set the background color of the header cells, nothing happens. if(role == Qt::BackgroundRole) return Qt::red; I set a breakpoint on the return and it is reached.

How to Move Up a Selected Row in Qt

╄→гoц情女王★ 提交于 2019-12-10 18:54:22
问题 I have a QTableView with 3 rows and 2 columns. (Here I am using a QStandardItemModel ). I want to move up/move down a single row when a QPushButton is clicked. How can I move up/down a row in QTableView ? Thanks for your reply vahancho. I have already tried using QAbstractItemModel::moveRow , but it doesn't work: int currentRow = ui->tableView->currentIndex().row(); QModelIndex sourceParent = ui->tableView->model()->index(ui->tableView->selectionModel()->currentIndex().row(),0); QModelIndex

How to inject widgets between QHeaderView and QTableView?

拥有回忆 提交于 2019-12-10 18:05:28
问题 I would like to display widgets between the QHeaderView and the rest of the QTableView , like in the example picture below (created with Photoshop) , as this seems like a natural way to enable input for filtering columns. Does anybody have any ideas of how to inject widgets inbetween? 回答1: Below is a demo of a FilterHeader class that I wrote for one of my own projects. You will probably need to adapt it to suit your own needs, but it should already do most what you want. The padding around