QHeaderView induvidual background colors
-
@JonB said in QHeaderView induvidual background colors:
class AdvHeaderView : public QHeaderView;
You are finding that your derived
AdvHeaderView
is not producing any signals, is that right? Did you putQ_OBJECT
macro in your declaration/definition ofAdvHeaderView
? Not sure, that may be required here?I seen that it produces no signals. Unfortunately Q_OBJECT wasn't the problem
class AdvHeaderView : public QHeaderView { Q_OBJECT public: AdvHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr) : QHeaderView(orientation, parent) {} protected: void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override; }
-
- Temporarily replace your
AdvHeaderView
with a plainQHeaderView
. Does the signal work? - Is it just the
sectionClicked()
signal which does not work or all signals do not work? - Make sure your
headerClicked()
has aqDebug()
so we are sure it not getting called and/or try a lambda with justqDebug()
in it as the slot.
- Temporarily replace your
-
@JonB said in QHeaderView induvidual background colors:
- Temporarily replace your
AdvHeaderView
with a plainQHeaderView
. Does the signal work? - Is it just the
sectionClicked()
signal which does not work or all signals do not work? - Make sure your
headerClicked()
has aqDebug()
so we are sure it not getting called and/or try a lambda with justqDebug()
in it as the slot.
If I reset the integrated HeaderView all works.
I had integrated debug messages.Signal SectionResized and GeomtryChaged work always. All Mouse Enter/Click/DoubleClick etc. dont work.
- Temporarily replace your
-
@Andy314
On yourAdvHeaderView
instance what does bool QHeaderView::sectionsClickable() const return? Do you need to call void QHeaderView::setSectionsClickable(bool clickable) withtrue
? -
@JonB said in QHeaderView induvidual background colors:
@Andy314
On yourAdvHeaderView
instance what does bool QHeaderView::sectionsClickable() const return? Do you need to call void QHeaderView::setSectionsClickable(bool clickable) withtrue
?Yeh, that was the problem. Thank you for the tip.
-
@JonB said in QHeaderView induvidual background colors:
as a base QHeaderView does.
Are you sure about that? Haven't checked the code but this from the documentation
Returns true if the header is clickable; otherwise returns false. A clickable header could be set up to allow the user to change the representation of the data in the view related to the header.
sounds like it's not the default in
QHeaderView
-
Are you sure about that?
No, I am not sure. I am relying on the OP's statement that with a non-subclassed
QHeaderView
in hisQTableView
clicking works (by default) while as soon as he sub-classes to shownAdvHeaderView
it does not work. And wondering how that would be. -
@JonB said in QHeaderView induvidual background colors:
And wondering how that would be.
It was enabled in the ui but since the header gets replaced in c++ it was overridden.
-
@Christian-Ehrlicher said in QHeaderView induvidual background colors:
It was enabled in the ui but since the header gets replaced in c++ it was overridden.
Ah, no wonder, at least that makes sense!
-
@JonB said in QHeaderView induvidual background colors:
@Andy314
What I do not know is why/how a derivedQHeaderView
does not get this set as a baseQHeaderView
does. Perhaps a Qt/C++ expert would care to enlighten us?That is exact the problem I struggled.
From the logic it can only be that the QTableView itself configures its QHeaderView correct.
Indeed I found the code for it:void QTableViewPrivate::init() { Q_Q(QTableView); q->setEditTriggers(editTriggers|QAbstractItemView::AnyKeyPressed); QHeaderView *vertical = new QHeaderView(Qt::Vertical, q); vertical->setSectionsClickable(true); vertical->setHighlightSections(true); q->setVerticalHeader(vertical); QHeaderView *horizontal = new QHeaderView(Qt::Horizontal, q); horizontal->setSectionsClickable(true); // Here is the code **************************** horizontal->setHighlightSections(true); q->setHorizontalHeader(horizontal); tabKeyNavigation = true; #if QT_CONFIG(abstractbutton) cornerWidget = new QTableCornerButton(q); cornerWidget->setFocusPolicy(Qt::NoFocus); QObject::connect(cornerWidget, SIGNAL(clicked()), q, SLOT(selectAll())); #endif }
-