qheaderview

Implement paintSection for QHeaderView delivered class

十年热恋 提交于 2020-01-05 00:48:20
问题 protected: virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const { QHeaderView::paintSection(painter, rect, logicalIndex); painter->drawRect(2, 2, 10, 10); } Rectangle is not painting. But when paintSection removed it is painting. I need to draw rectangle after call base paintSection. 回答1: As it was answered in this your question, rect is an area your should paint at. If you paint outside of this area your drawings might be erased by painting of other cells.

Adding Vertical headers to a QTreeView

大兔子大兔子 提交于 2020-01-01 17:10:46
问题 I have a QTreeView subclass (and QAbstractItemModel subclass) which has a nice horizontal header. I would like to add vertical headers (going down the left side) to match. But unlike QTableView which has separate vertical (setVerticalHeader()) and horizontal headers (setHorizontalHeader()), QTreeView only allows a single header (setHeader()). I know that I can just pretend that the leftmost column is the header and render it with a different background color (I don't need the ability to

What does QHeaderView::paintSection do such that all I do to the painter before or after is ignored

此生再无相见时 提交于 2019-12-28 06:51:22
问题 This question is further development of this post and is different, though may seem similar as this one. I am trying to reimplement QHeaderView::paintSection , so that the background returned from the model would be honored. I tried to do this void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const { QVariant bg = model()->headerData(logicalIndex, Qt::Horizontal, Qt::BackgroundRole); // try before if(bg.isValid()) // workaround for Qt bug https://bugreports

Header to a TableView

▼魔方 西西 提交于 2019-12-13 03:30:33
问题 I've been browsing everywhere and I just cannot find any information on how to create a certain type of header to a TableView in Qt Creator. I want it to look similar to this: 回答1: short answer: there is no settings in the QTCreator that you can set to define the Header of a table view... long answer: That is a TableView with custom model. you need then to define a new Model that inherits the QAbstractTableModel and then in tne FooModel header override the headerData method class FooModel :

Read model data with custom QHeaderView

回眸只為那壹抹淺笑 提交于 2019-12-12 05:39:48
问题 I want to set a custom QHeaderView to rotate the horizontal header's text. I'm working with a QStandarItemModel For the moment I've this class QHeaderViewR : public QHeaderView { public: QHeaderViewR():QHeaderView(Qt::Horizontal) {} void paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const { QPen pen(Qt::black); painter->setPen(pen); painter->translate(rect.width() * logicalIndex, (logicalIndex * -18) -18); painter->rotate(90); painter->drawText(rect,"header"); } }; I

Change QHeaderView data

可紊 提交于 2019-12-11 20:44:33
问题 I try to modify the text of my QHeaderView (Horizontal) in my QTableWidget. First question: Is it possible to set it editable like a QTableWidgetItem ? Second question: If it's not possible, how can I do that, I tried to repaint it like this: void EditableHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const { painter->save(); QHeaderView::paintSection(painter, rect, logicalIndex); painter->restore(); painter->setPen(Qt::SolidLine); painter->drawText(rect, Qt:

PyQt5 column sorting not working when using custom HeaderView

旧街凉风 提交于 2019-12-11 06:01:40
问题 I'm trying to create a TableView with sorting functionality. If I set the TableView obj my custom HeaderView , clicking on the header won't sort, even though my custom HeaderView re-implements nothing. If I use instead the TableView 's header ( hh=tv.horizontalHeader() ) it sorts. What am I doing wrong? Code below: import sys import operator from PyQt5 import QtWidgets from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant class TableModel(QAbstractTableModel): def __init__(self, parent,

How to inject widgets between QHeaderView and QTableView?

拥有回忆 提交于 2019-12-10 18:05:28
问题 I would like to display widgets between the QHeaderView and the rest of the QTableView , like in the example picture below (created with Photoshop) , as this seems like a natural way to enable input for filtering columns. Does anybody have any ideas of how to inject widgets inbetween? 回答1: Below is a demo of a FilterHeader class that I wrote for one of my own projects. You will probably need to adapt it to suit your own needs, but it should already do most what you want. The padding around

Spanning horizontal header in Qt

喜夏-厌秋 提交于 2019-12-09 18:34:14
问题 I want to merge(span) horizontal headers in QTableWidget . I tried googling for the same, but no luck and hence posting it. Please guide me. 回答1: You can subclass QHeaderView and create one section for each of the groups of columns/rows you would like to span and connect signals and slots to have them react to the different columns/rows. The following example is for spanning the horizontal header: #include <QtGui> class MyHeaderModel : public QAbstractItemModel { public: MyHeaderModel(QObject

How to draw text in derived from QHeaderView class

为君一笑 提交于 2019-12-08 04:02:18
问题 I need to draw text in derived from QHeaderView class. But this code does not work. void HeaderView::paintSection(QPainter *painter, const QRect &, int) const { painter->drawText(0, 0, "abcde"); } 回答1: The documentation says: Paints the section specified by the given logicalIndex, using the given painter and rect. That means, you have to use the rect getting as parameter: void HeaderView::paintSection(QPainter *painter, const QRect& rect, int) const { painter->drawText(rect, Qt::AlignCenter,