qtableview

Qt QAbstractModel: remove checkbox

半城伤御伤魂 提交于 2019-12-12 06:27:16
问题 I started to learn Qt, and I would like to implement a table filled with data via QTableView. My problem is, that I don't know how to remove the checkboxes from the cells. It seems like they are put in by default. However, I read that I had to return a NULL-QVariant, but that's not what I was looking for as I still have data to put in. That's my code so far: QVariant MyModel::data(const QModelIndex &index, int role) const { int row = index.row(); int col = index.column(); QString daten;

Remove the vertical grid lines of a QTableView

不羁的心 提交于 2019-12-12 03:44:40
问题 I have a QTableView as shown below: I want to remove all the vertical lines from the table. I tried to set the gridline-color property equivalent to the background-color , but it removed all the grid lines. I want the horizontal grid lines to stay, and remove the vertical ones. How can I achieve that ? 回答1: delegate.h class QLineDelegate : public QStyledItemDelegate { public: QLineDelegate(QTableView* tableView); protected: void paint(QPainter* painter, const QStyleOptionViewItem& option,

Specializing a QAbstractProxyModel for adding a column: the table cells becomes empty

老子叫甜甜 提交于 2019-12-12 02:43:27
问题 I have created a mixin-like proxy model (Qt5) which just adds an extra first column to another proxy model, for adding a QToolBar of actions to each row of the table view (for example, a "delete" button). The model just provides a way of populating a QList<QVariant> for the first column. The delegate must know what is the meaning of each QVariant (usually int s/ enum s identifying actions), and populate the QToolBar accordingly. As last feature, if there's no actions, no extra column is added

QTableView How can I highlight the entire row for mouse hover?

微笑、不失礼 提交于 2019-12-11 19:32:19
问题 The selection behavior is set to select rows, but only the hovered cell is highlighted. Is there any way to highlight the entire row? 回答1: There are 2 ways.. 1) You can use delegates to draw the row background... You will need to set the row to highlight in the delegate and based on that, do the highlighting. 2) Catch the signal of current row. Iterate over the items in that row and set background for each item. Hope, It will usefull to you guys. 回答2: First, you subclass QTableWidget

how to add widgets in every a qtableView cell with a MVC design?

北战南征 提交于 2019-12-11 15:45:00
问题 Here is a simple example of a qtableView where every cell have a different item. In the example here i used numbers, but ultimately i wish to display animated gifs for every cells. I wish to keep the MVC design and insert a custom widget proceduraly. import random import math from PyQt4 import QtCore, QtGui class TableModel(QtCore.QAbstractTableModel): def __init__(self, data, columns, parent=None): super(TableModel, self).__init__(parent) self._columns = columns self._data = data[:] def

PyQt - QCombobox in QTableview

自作多情 提交于 2019-12-11 15:16:23
问题 I am displaying data from an SQLite database in a QTableView using a QSqlTableModel. Letting the user edit this data works fine. However, for some columns I want to use QComboboxes instead of free text cells, to restrict the list of possible answers. I have found this SO answer and am trying to implement it on my model/view setting, but I'm running into problems (so this is a follow-up). Here's a full mini-example: #!/usr/bin/python3 # -*- coding: utf-8 -*- from PyQt5 import QtSql from PyQt5

Qt5 - QTableView with QtSql

不羁的心 提交于 2019-12-11 10:11:41
问题 This is a bit of a follow on question from this one - Python referencing database connection on another script After managing to get my connection and pull data from the database, I read that using QTableView, as opposed to QTableWidget would be better for what I am trying to achieve. However, I've been struggling to get the table to populate using QTableView, and nearly every example I can find is in C++, rather than Python, and there are so many different terminologies used, it's like a

Custom sorting method of QTableView?

落爺英雄遲暮 提交于 2019-12-11 09:28:48
问题 How can I setup custom sorting method for a QTableView , or for the model ? (Which function should I re-implement) The default sorting algorithm are for strings , I want a number sorting method for some specific column. Thanks. 回答1: You should use QSortFilterProxyModel. You should reimplement lessThan method. Then you have to set sourceModel for your proxy model, and set your proxy model as model for your view class MyProxyModel: public QSortFilterProxyModel { protected: bool lessThan ( const

QTableView not expanding/reducing when QMainWindow is resized

强颜欢笑 提交于 2019-12-11 09:04:24
问题 I have a QMainWindow. Inside the QMainWindow, I have a central widget. For the central widget, I have a QVBoxLayout. To this QVBoxLayout, I've added 3 widgets. One is a widget with some labels, which has a QGridLayout. The other is a horizontal line. The third is a QTableView. The problem is that when I try and expand the QMainWwindow, despite whatever resize policy I set ( or not), the TableView does not expand, and it leaves an ungainly blank area in the rest of the expanded QMainWindow.

QStandardItemModel inside Qtableview

倖福魔咒の 提交于 2019-12-11 08:49:12
问题 I am using QStandardItemModel inside QTableView . Here i have two button & Qtableview inside my mainwindow. I need only 4 columns inside this. And rows will vary. The two Buttons will be used to add/delete a row (test case). setHorizontalHeaderItem is not showing all the text(means all text is not visible). Example if i put 'Text for the Employee Name' it is not fully visible ? How to make QStandardItemModel occupy full QTableview ( width ). At present it is showing at top left corner ? How