qtableview

checkbox and itemdelegate in a tableview

只谈情不闲聊 提交于 2019-11-29 21:56:35
问题 I'm doing an implementation of a CheckBox that inherits from QitemDelegate, to put it into a QTableView. the problem is that I get when inserted flush left and I need it centered. As I understand the method that is responsible for the Paint. I have it written as follows: void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { bool checkValue; QStyleOptionButton BtnStyle; BtnStyle.state = QStyle::State_Enabled; if(index.model()-

how to get selected rows in QTableView

╄→尐↘猪︶ㄣ 提交于 2019-11-29 20:53:39
After watching many threads about getting selected rows numbers, I am really confused. How do you get ROW numbers in QTableView using QStandardItemModel I used below selection model and behavior as setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); and if you have your own way of selecting can you explain how it works. Thanks for the help! Luca The method selectionModel() return a QItemSelectionModel . You can use QItemSelectionModel class to check/change/other selection(s) Example: QItemSelectionModel *select = table->selectionModel();

How to Copy - Paste Multiple Items form QTableView created by QStandardItemModel to a text/excel file?

*爱你&永不变心* 提交于 2019-11-29 16:52:32
How can I copy and paste multiple items/values of a QTableView to a text/ excel file? 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.QRect(0, 0, 721, 571)) self.model = QtGui.QStandardItemModel(self) self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection This line self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection helps with selecting multiple items in QTableView but when I do CTRL + C and paste it only pastes the last item or value

Copy/Paste multiple items from QTableView in pyqt4?

梦想与她 提交于 2019-11-29 12:47:01
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.QRect(0, 0, 721, 571)) self.model = QtGui.QStandardItemModel(self) self.model.setSortRole(QtCore.Qt

Paste in the field of QTableView

 ̄綄美尐妖づ 提交于 2019-11-29 12:15:07
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__(self,md,parent=None): QWidget.__init__(self,parent) # initially construct the visible table self.tv

PyQt QTableView prohibitively slow when scrolling with large data sets

为君一笑 提交于 2019-11-29 06:58:51
I have a program that loads a profile from a csv file and displays the data in a table. The loading of a pandas data frame to the table is fast because I used a custom model implementation of QAbstractTableModel , but the resizing of the QTableView widget is incredibly slow. What can I do to make the resizing and scrolling smoother? Well, I ended up modifying the custom table model I made to use numpy, and now it is blazing fast. Use this table model: import numpy as np class PandasModel(QtCore.QAbstractTableModel): """ Class to populate a table view with a pandas dataframe """ def __init__

Qt - QTableView - Clickable button in table row

蹲街弑〆低调 提交于 2019-11-29 05:44:05
问题 I require a button/link within a table row of a QTableView . This is to open a dialog to allow that row to be edited more efficiently. After hours of looking on the web I am yet to find a decent example. I am aware that this is likely to be done using a QItemDelegate , but I am unsure how to have a functional widget within the row without forcing the item into edit mode first. Any help would be greatly appreciated. 回答1: You could emulate the functionality of a link by underlining the

How to create a filter for QTableWidget?

爱⌒轻易说出口 提交于 2019-11-29 05:11:00
I'm trying to create a filter for QTableWidget with QLineEdit in PySide. I've seen some tutorials using QSortFilterProxyModel for C++ but couldn't understood how to do it in Python. I need to search in 'VALUE' column. Trilarion A QSortFilterProxyModel is a proxy model, that means that you put it between the your complete data model and a view. The comment by titusjan is good, you can look in your local PySide/PyQt installation for basicsortfiltermodel.py to get an example in Python. Also, instead of using a QTableWidget a QTableView is sufficient - you won't need the inbuilt model of

QTableView output save as .csv or .txt

夙愿已清 提交于 2019-11-29 02:28:22
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(); if (db.open()) { qDebug()<<QDateTime::currentDateTime()<<"QUERY DONE SUCCESSFULLY "; this->model=new

Set color to a QTableView row

倖福魔咒の 提交于 2019-11-29 02:14:58
void MyWindow::initializeModelBySQL(QSqlQueryModel *model,QTableView *table,QString sql){ model = new QSqlQueryModel(this); model->setQuery(sql); } With this method i can set a QSQlQueryModels to my QTableviews. But How i can set color to a row based on a cell value? The view draws the background based on the Qt::BackgroundRole role of the cell which is the QBrush value returned by QAbstractItemModel::data(index, role) for that role. You can subclass the QSqlQueryModel to redefine data() to return your calculated color, or if you have Qt > 4.8, you can use a QIdentityProxyModel : class MyModel