qtableview

Qt QTableView draw border around active cells

本小妞迷上赌 提交于 2019-12-05 06:37:59
I'm trying to implement behavior similar Excel in a QTableView, where a border is painted around the entire current selection. I have tried this what feels like a hundred different ways and keep getting problems. I can draw the border easily enough, but remnants of the border are left whenever the selection changes. Here is one example I've tried in QTableView::paintEvent ... void MyTableView::paintEvent(QPaintEvent* event) { // call QTableView's paint event first so we can draw over it QTableView::paintEvent(event); // activeSelection is a list of indexes that is updated in another function /

How to trigger the edit mode of an item in a QTableView?

≡放荡痞女 提交于 2019-12-05 04:35:36
I'm using QTableView and QStandardItemModel now. In the QTableView, if you double-click a cell, this cell will get into edit mode and you can edit its content. Now I have a problem, I want to trigger the edit mode of an item by code (by command), what should I do? I cannot find proper function or slot in QTableView or QStandardItemModel. Do I need to emit any signal to get into edit mode? And which signal I should catch if I want to know when the editing is finish (user press "Enter" or click another items to leave the edit mode)?? Thanks for your help See : void QAbstractItemView::edit (

Read and write to a file from a QTableView

时光总嘲笑我的痴心妄想 提交于 2019-12-05 03:56:36
问题 How can I read and write to a text file date enter to a QTableView? This is what I have but I would like to save the data when it is added to the table and of course be able to read it back when the application is reopened. Is there any tutorial I can refer to? MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QStandardItemModel(); model->setRowCount(0); ui->tableView->setModel(model); } MainWindow::~MainWindow() { delete ui

QTableView column width

那年仲夏 提交于 2019-12-05 03:42:27
I'm struggling to set column width manually in a QTableView . Why doesn't this piece of code work? tabb = new QTableView; tabb->resizeColumnsToContents(); for (int col=0; col<20; col++) { tabb->setColumnWidth(col,80); } If I omit tabb->resizeColumnsToContents(); it still doesn't work. You should set model first and after this you will be able to change ColumnWidth : tabb = new QTableView; tabb->setModel(someModel); for (int col=0; col<20; col++) { tabb->setColumnWidth(col,80); } 来源: https://stackoverflow.com/questions/26681578/qtableview-column-width

Change QSortFilterProxyModel behaviour for multiple column filtering

风流意气都作罢 提交于 2019-12-05 01:22:55
问题 We have a QSortFilterProxyModel installed on a QTableView and two (or more) QLineEdit for filtering the view (based on the text of these QLineEdit s) In our view we have a slot that tells us the string of lineedits and the current column that we want. Something like this : void onTextChange(int index, QString ntext) { filter.setFilterKeyColumn(index); filter.setFilterRegExp(QRegExp(ntext, Qt::CaseInsensitive)); } On the first column we have names in the second we have year of birthday. Now we

Show image in a column of QTableView from QSqlTableModel

若如初见. 提交于 2019-12-04 11:44:29
问题 I'm curious about how I can display an image from my database in a QTableView . Is there something like QTableWidgetItem that I am able to use it in QTableView ? I use QSqlTableModel . 回答1: A rough idea is to use QStandardItem::setData to set a QPixmap (transformed into QVariant ) on it, then you can set the QStandardItem on the QStandardItemModel. Sequence: QImage ---> QPixmap ---> QVariant ---> QStandardItem ---> QStandardItemModel For example: QStandardItemModel *model = new

What is the best way to display an animated icon in a QTableView?

别说谁变了你拦得住时间么 提交于 2019-12-04 10:34:48
问题 I've been struggling with this for some times now, and I can't seem to find the right way to do this. What I would like is the ability to use an animated icon as a decoration for some of my items (typically to show that some processing is occuring for this particular item). I have a custom table model, that I display in a QTableView . My first idea was to create a custom delegate that would take care of displaying the animation. When passed a QMovie for the decoration role, the delegate would

How to sort a QTableWidget with my own code?

橙三吉。 提交于 2019-12-04 06:38:16
I am using Qt4.5.2 on Linux. I have a simple QTableWidget, in which a column displays dates in a human-friendly format. Unfortunately "human-friendly dates" are not easy to sort correctly. So, in the QTableWidget I keep a hidden column with the UNIX timestamp corresponding to that date. I am trying to make sure that, whenever a request to sort on the DATE column is issued, in reality the sort be done on the (invisible) TIMESTAMP column. I tried reimplementing sortByColumn (this is in Python) by subclassing from QTableWidget and defining: def sortByColumn(self, col, order): print 'got request

Adding checkBox as vertical header in QtableView

假如想象 提交于 2019-12-04 05:22:24
问题 I am trying to have a QTableView of checkboxes, so I can use them for row selections... I have managed to do that, now I want the header Itself to be checkbox so I can check/Uncheck All or any row . I have been looking for days, but couldn't get to do it. I tried to use setHeaderData to the model, but couldn't do it. Any help would be appreciated. 回答1: I wasn't particularly happy with the C++ version that @tmoreau ported to Python as it didn't: handle more than one column handle custom header

Select rows and columns in QTableWidget, while keeping highlighted

早过忘川 提交于 2019-12-04 05:02:52
问题 I have a QTableWidget that I've set up such that you can't select the cells, but can select rows/columns by their headers. The problem I'm having is when I select a row, it deselects any columns that were selected, and same for column/rows. I want to be able to select rows with the ExtendedSelection behavior and columns with the SingleSelection behavior, but independently of eachother. Here's what I'm doing: ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection); connect(ui-