Give focus to QGraphicsView without stealing focus from Qbutton
-
wrote on 17 Jun 2023, 13:25 last edited by Narutoblaze
I have sidebar which have multiple Qbutton to switch between pages of a stackedwidget to let the user know which page they are in based on button clicked, i am using stylesheet Qbutton:focus but i also have custom QGraphicsView and handling keypressevent and the problem is clicking on QGraphicsView steals the focus from button what can be the solution ?
Snippet how my code look :
Qbutton:focus { background-color:rgb(40,40,40) }
class cutomView : public QGraphicsView { public: // etc protected: void KeyPressEvent(QKeyEvent *event) override; }
-
@mpergand Thanks for responding, i have tried this now but issue is i have to click again or else it stays clicked in Qbutton:focus it automatically unclick a Qbutton when clicked another Qbutton.
wrote on 17 Jun 2023, 14:49 last edited byAdd all of your buttons which control the stackedWidget to a
QButtonGroup
and make it exklusive withsetExclusive
-
I have sidebar which have multiple Qbutton to switch between pages of a stackedwidget to let the user know which page they are in based on button clicked, i am using stylesheet Qbutton:focus but i also have custom QGraphicsView and handling keypressevent and the problem is clicking on QGraphicsView steals the focus from button what can be the solution ?
Snippet how my code look :
Qbutton:focus { background-color:rgb(40,40,40) }
class cutomView : public QGraphicsView { public: // etc protected: void KeyPressEvent(QKeyEvent *event) override; }
wrote on 17 Jun 2023, 13:48 last edited by@Narutoblaze
try:
QPushButton:checked{ background-color: rgb(40,40,40) -
@Narutoblaze
try:
QPushButton:checked{ background-color: rgb(40,40,40)wrote on 17 Jun 2023, 14:16 last edited by Narutoblaze@mpergand Thanks for responding, i have tried this now but issue is i have to click again or else it stays clicked in Qbutton:focus it automatically unclick a Qbutton when clicked another Qbutton.
-
@mpergand Thanks for responding, i have tried this now but issue is i have to click again or else it stays clicked in Qbutton:focus it automatically unclick a Qbutton when clicked another Qbutton.
wrote on 17 Jun 2023, 14:49 last edited byAdd all of your buttons which control the stackedWidget to a
QButtonGroup
and make it exklusive withsetExclusive
-
@mpergand Thanks for responding, i have tried this now but issue is i have to click again or else it stays clicked in Qbutton:focus it automatically unclick a Qbutton when clicked another Qbutton.
wrote on 17 Jun 2023, 14:49 last edited by@Narutoblaze
You have to call setAutoExclusive(true)
for all the buttons. -
wrote on 17 Jun 2023, 16:27 last edited by
-
-
-
3/6