qtableview

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

我是研究僧i 提交于 2020-01-25 21:28:00
问题 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

PyQt: How to sort QTableView columns(strings and numericals)

拟墨画扇 提交于 2020-01-24 20:27:12
问题 The line self.tableView.setSortingEnabled(True) sorts a table view when clicking on the header, but it sorts incorrectly. That is, it thinks every column is a string (e.g. it sorts numbers like 1,11,12,2,22,3 , etc). How do I correct this? My code: self.model = QtGui.QStandardItemModel() with open(file_name_temp, "rt") as fileInput: i = 1 for row in csv.reader(fileInput): item = QtGui.QStandardItem() for field in row: items = [ item.setData(field, QtCore.Qt.UserRole) ] print(items) self.model

QTableView external drag and drop

断了今生、忘了曾经 提交于 2020-01-05 15:15:47
问题 Is there a way to drag rows out of a QTableView? I know how to internally move columns within a QTableView by configuring some properties on the view: table_view_->horizontalHeader()->setSectionsMovable(true); table_view_->horizontalHeader()->setDragEnabled(true); table_view_->horizontalHeader()->setDragDropMode(QAbstractItemView::InternalMove); Going through the documentation on QAbstractItemView::DragDropMode , I intuitively expected my following attempt to allow external dragging of

QTableView output save as .csv or .txt

故事扮演 提交于 2019-12-29 05:29:04
问题 I wrote the below code for a qt gui to view the query output in a QTableView(Model oriented). now i want to save this output as a .csv or .txt file. There were suggestions to use QTableWidget(Item oriented) but I would like to stick to the model based approach. void MainWindow::on_pushButton_clicked() { db = QSqlDatabase::addDatabase("QOCI"); db.setHostName("host"); db.setDatabaseName("db"); db.setUserName("uid"); db.setPassword("pw"); db.setPort(port); QString MyQuery = ui->lineEdit->text();

How to display a Pandas data frame with PyQt5/PySide2

落花浮王杯 提交于 2019-12-27 11:59:46
问题 I have a problem with the line below self.tableView.set??????????(df) that supposed to display the data frame in PyQt5. I put ??? there where I am missing the code I need. def btn_clk(self): path = self.lineEdit.text() df = pd.read_csv(path) self.tableView.set??????????(df) The rest of the code works, because if I use print(df) in the above code, the data frame is printed in the IPython console. So, Pandas reads the CSV and prints it. But, I tried many things to get it displayed in PyQt5 and

QTableView with QStandardItemModel: How to perform live updates during editing a cell?

假如想象 提交于 2019-12-25 17:10:13
问题 Recently, I made the switch to QT. It has taken some time, but I am starting to find my way around. However, one issue remains: I want to port a program, that responds to every key press while editing a cell in a table view (QTableView with QStandardItemModel). The idea is to show and update a list of possibilities on a separate form while the user is entering a text in a table view's cell. After every key stroke, the list needs to be updated according to the current text in the edit field of

PyQt5 Extremely Slow Scrolling on QTableView with pandas

柔情痞子 提交于 2019-12-25 03:19:46
问题 I am creating a table inside of a PyQt5 GUI using QTableView. I have 35 rows and 5 columns from a pandas dataframe. Scrolling and sorting the table is extremely slow (on the order of seconds). I have already looked for solutions, but most people were having trouble with populating the table. One person suggested using a numpy array, but I did not see any increase in performance. Here is my code: def create_table(dataframe): table = QTableView() tm = TableModel(dataframe) table.setModel(tm)

PyQt5 Extremely Slow Scrolling on QTableView with pandas

房东的猫 提交于 2019-12-25 03:19:12
问题 I am creating a table inside of a PyQt5 GUI using QTableView. I have 35 rows and 5 columns from a pandas dataframe. Scrolling and sorting the table is extremely slow (on the order of seconds). I have already looked for solutions, but most people were having trouble with populating the table. One person suggested using a numpy array, but I did not see any increase in performance. Here is my code: def create_table(dataframe): table = QTableView() tm = TableModel(dataframe) table.setModel(tm)

Adding CheckBox with QSqlQueryModel shown in QTableview and other columns are empty

拟墨画扇 提交于 2019-12-25 01:46:34
问题 I am using the code in this answer to add checkbox in tableview. I want to show it in the first column. Here is my code: mysqlquerymodel.h #ifndef MYSQLQUERYMODEL_H #define MYSQLQUERYMODEL_H #include <QObject> #include <QMap> #include <QModelIndex> #include <QSqlQueryModel> class MySqlQueryModel : public QSqlQueryModel { Q_OBJECT public: explicit MySqlQueryModel(QObject *parent = 0); Qt::ItemFlags flags(const QModelIndex & index) const; QVariant data(const QModelIndex & index, int role) const

How to get Index Row number from Source Model

…衆ロ難τιáo~ 提交于 2019-12-25 01:08:58
问题 Clicking the QTableView " Item_B_001 " prints out its row number # 0 . But in source model's self.items this item corresponds to the number # 3. How to get a "real" Source Model's Item's row number - a number it really corresponds to? from PyQt4.QtCore import * from PyQt4.QtGui import * import sys class Model(QAbstractTableModel): def __init__(self, parent=None, *args): QAbstractTableModel.__init__(self, parent, *args) self.items = ['Item_A_001','Item_A_002','Item_B_001','Item_B_002'] def