Disable selection for vertical/horizontal header - QTableWidget
-
wrote on 14 Jun 2021, 23:42 last edited by
-
Basically I don't want this:
or this:I have tried these but they don't work:
ui->table->verticalHeader()->setSelectionMode(QAbstractItemView::NoSelection); ui->table->horizontalHeader()->setSelectionMode(QAbstractItemView::NoSelection);
wrote on 15 Jun 2021, 06:30 last edited by JonB@hbatalha
Does QHeaderView::setHighlightSections(false) do what you want?
[EDIT: Maybe not, since it says "By default, this property is false.", yet it does sound to me like it should be this?] -
@hbatalha
Does QHeaderView::setHighlightSections(false) do what you want?
[EDIT: Maybe not, since it says "By default, this property is false.", yet it does sound to me like it should be this?] -
@hbatalha
Does QHeaderView::setHighlightSections(false) do what you want?
[EDIT: Maybe not, since it says "By default, this property is false.", yet it does sound to me like it should be this?]wrote on 16 Jun 2021, 14:27 last edited by@JonB However... QHeaderView::setSectionsClickable(false)
ui->table->horizontalHeader()->setSectionsClickable(false);
Even thought it is not made for that purpose but it does solve this particular problem of mine.
-
-
Hi
It does disable it showing it on the headers.
but you want to disable user can click on it to select the row?
update:
well yeah setSectionsClickable should do it :)wrote on 16 Jun 2021, 14:31 last edited by@mrjj said in Disable selection for vertical/horizontal header - QTableWidget:
but you want to disable user can click on it to select the row?
No, I just wanted the headers not to get highlighted when the user hover the mouse.
-
@mrjj said in Disable selection for vertical/horizontal header - QTableWidget:
but you want to disable user can click on it to select the row?
No, I just wanted the headers not to get highlighted when the user hover the mouse.
ok but even if setSectionsClickable(false); does kill this ability for the user, its ok solution ?
-
ok but even if setSectionsClickable(false); does kill this ability for the user, its ok solution ?
wrote on 16 Jun 2021, 14:37 last edited by@mrjj said in Disable selection for vertical/horizontal header - QTableWidget:
its ok solution ?
Not quite, for example for the vertical header it kills its ability to get selected when its row is selected.
-
@mrjj said in Disable selection for vertical/horizontal header - QTableWidget:
its ok solution ?
Not quite, for example for the vertical header it kills its ability to get selected when its row is selected.
@hbatalha
Hi
I tried to grab the hover eventclass test : public QHeaderView { Q_OBJECT public: explicit test(Qt::Orientation orientation, QWidget *parent = nullptr ) : QHeaderView(orientation, parent) {} protected: bool event(QEvent *e) override { if ( e->type() == QEvent::HoverEnter ) return true; return QHeaderView::event(e); } };
but that broke selection too.
so I didn't find a way to get rid of that coloring as it seems mostly to go on inside the d-> private section. -
@hbatalha
Hi
I tried to grab the hover eventclass test : public QHeaderView { Q_OBJECT public: explicit test(Qt::Orientation orientation, QWidget *parent = nullptr ) : QHeaderView(orientation, parent) {} protected: bool event(QEvent *e) override { if ( e->type() == QEvent::HoverEnter ) return true; return QHeaderView::event(e); } };
but that broke selection too.
so I didn't find a way to get rid of that coloring as it seems mostly to go on inside the d-> private section. -
@mrjj I tried to grab hover through stylesheet but didn't work.
I guess selection is a small price to pay to get it done. At least until I find a better way.
Yeah, I guess so too. at least until a better way comes as the things i tried would then
break selection and no better than setSectionsClickable -
For Qt6 you can override QHeaderView::initStyleOptionForIndex().
-
For Qt6 you can override QHeaderView::initStyleOptionForIndex().
wrote on 16 Jun 2021, 18:50 last edited by@Christian-Ehrlicher could you provide a minimal working example?
-
I currently see that setHighlightSections() should also work.
could you provide a minimal working example?
call the base class impl and then modify QStyleOptionHeader::state the way you want.
1/14