qtableview

How do I resize rows with setRowHeight and resizeRowToContents in PyQt4?

扶醉桌前 提交于 2020-05-16 02:28:48
问题 I have a small issue with proper resizing of rows in my tableview. I have a vertical header and no horizontal header. I tried: self.Popup.table.setModel(notesTableModel(datainput)) self.Popup.table.horizontalHeader().setVisible(False) self.Popup.table.verticalHeader().setFixedWidth(200) for n in xrange(self.Popup.table.model().columnCount()): self.Popup.table.setColumnWidth(n,150) And this works fine, but when I try: for n in xrange(self.Popup.table.model().rowCount()): self.Popup.table

Catch double click in QTableView's unused area

£可爱£侵袭症+ 提交于 2020-04-07 06:55:46
问题 My application starts with an empty table, and I want to imlement different methods to add items. One should be by double-clicking the table's unused area (or "background") that is not occupied by any cells. When a cell is double-clicked, I want the default behavior. I've found way to do this by re-implementing QAbstractScrollArea::mouseDoubleClickEvent() method in my TestTable class: #include <QMouseEvent> #include <QTableView> class TestTable : public QTableView { Q_OBJECT signals: void

Catch double click in QTableView's unused area

为君一笑 提交于 2020-04-07 06:55:33
问题 My application starts with an empty table, and I want to imlement different methods to add items. One should be by double-clicking the table's unused area (or "background") that is not occupied by any cells. When a cell is double-clicked, I want the default behavior. I've found way to do this by re-implementing QAbstractScrollArea::mouseDoubleClickEvent() method in my TestTable class: #include <QMouseEvent> #include <QTableView> class TestTable : public QTableView { Q_OBJECT signals: void

Create PushButtons in QTableView with QStyledItemDelegate subclass

假装没事ソ 提交于 2020-03-18 08:54:52
问题 I have the exact same problem, but I will use the QTableView widget. I read this and was wondering if I can override the createEditor function to use for instance QFileDialog to get the new data. If this is possible, can anyone provide me with an example to implement such a subclass to QItemDelegate. And if not, can anyone provide me with an example to implement a subclass to QItemDelegate, witch can draw a button next to a QLineEdit to get the functionality here. Edit: Maybe this question is

四十九、Qt之QTableView之单元格内文字居中、根据内容自动调整列宽

前提是你 提交于 2020-03-07 03:05:52
一、单元格内文字居中 CustomSqlQueryModel.h # ifndef CUSTOMSQLQUERYMODEL_H # define CUSTOMSQLQUERYMODEL_H # include <QObject> # include <QSqlQueryModel> class CustomSqlQueryModel : public QSqlQueryModel { public : CustomSqlQueryModel ( QObject * parent = 0 ) ; // QAbstractItemModel interface public : QVariant data ( const QModelIndex & index , int role ) const override ; } ; # endif // CUSTOMSQLQUERYMODEL_H CustomSqlQueryModel.cpp # include "customsqlquerymodel.h" CustomSqlQueryModel :: CustomSqlQueryModel ( QObject * parent ) : QSqlQueryModel ( parent ) { } /** * @brief 实现单元格内文字居中 */ QVariant

QTableView QAbstractTableModel QStyledItemDelegate QHeaderView 定制化表格(二)

不羁的心 提交于 2020-03-06 01:40:42
一、效果图 二、工程构建思路 依据mvc模型,重写QTableView QAbstractTableModel QStyledItemDelegate QHeaderView,利用QStyleOptionProgressBar自定义进度条样式,重写createEditor等必要函数实现自定义编辑输入框。 三、代码片段 //样式代理部分 # include "tabledelegate.h" TableDelegate :: TableDelegate ( QObject * parent ) : QStyledItemDelegate ( parent ) { } void TableDelegate :: paint ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const { //去掉Focus QStyleOptionViewItem viewOption ( option ) ; initStyleOption ( & viewOption , index ) ; if ( option . state . testFlag ( QStyle :: State_HasFocus ) ) viewOption . state =

sqlite view定义查询页面

泄露秘密 提交于 2020-03-02 00:32:57
下面想象一个这样的场景,你的数据库有一个表中储存有用户信息,姑且称为user表。 .schema user CREATE TABLE user(id integer,name text,telphone text,unique(id)); 表user中储存有 id: 相当于用户的实际ID,唯一 name: 用户的用户名,供显示或者登录的时候使用 telphone:一个附加信息,电话号码 一般我们程序中还会有一个储存用户数据的表,这里引用为data表,里面储存的是一些用户数据,完全可以自定义。在多用户的情况下我们一般会添加一个字段user_id来表示这个数据的所属用户。 .schema data CREATE TABLE data(message text,time datetime,user_id integer); 这是一个简单的场景,现在我们的需求是 提供一个用户界面,可以显示出 姓名,时间,信息 我们需要怎么做呢,(这里不提我曾经见过的一个中规模程序中逻辑控制拼接这些信息的了,代码冗余且丑陋,性能更不用提~) 我们在数据库中创建一个view来解决(引用为view1): .schema view1 CREATE VIEW view1 as select (select name from user where id=data.user_id) as name,time

Copy/Paste multiple items from QTableView in pyqt4?

谁说我不能喝 提交于 2020-01-27 08:33:14
问题 We can select multiple items(partial rows and partial columns) from QTableView using self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection) , but after selecting some rows and columns(partial and partial) if I do CTRL + C and paste it in notepad it only pastes one item(one value from the tableView)? 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

Copy/Paste multiple items from QTableView in pyqt4?

一曲冷凌霜 提交于 2020-01-27 08:32:24
问题 We can select multiple items(partial rows and partial columns) from QTableView using self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection) , but after selecting some rows and columns(partial and partial) if I do CTRL + C and paste it in notepad it only pastes one item(one value from the tableView)? 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

PyQt: QTableView + QSqlTableModel - Copy and Paste All Selected Rows or Columns into Notepad or Excel

亡梦爱人 提交于 2020-01-25 21:28:12
问题 To start, I've already looked at ekhumoro's code on a nearly similar subject Here. However, when I attempt to implement this code, I am getting a different result. Instead of copying and pasting all the I selected, it only copies the first cell of the selected row or rows respectively. I need users to be able to select multiple rows or columns and paste those values in either excel or notepad. Any ideas? GUI: Code: from PyQt4 import QtCore, QtGui, QtSql import sys import sqlite3 import time