Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Give focus to QGraphicsView without stealing focus from Qbutton

Give focus to QGraphicsView without stealing focus from Qbutton

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsviewkeyeventfocus
6 Posts 3 Posters 628 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • NarutoblazeN Offline
    NarutoblazeN Offline
    Narutoblaze
    wrote on last edited by Narutoblaze
    #1

    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;
    }
    
    M 1 Reply Last reply
    0
    • NarutoblazeN 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.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #4

      @Narutoblaze

      Add all of your buttons which control the stackedWidget to a QButtonGroup and make it exklusive with setExclusive

      • https://doc.qt.io/qt-6/qbuttongroup.html#exclusive-prop

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2
      • NarutoblazeN 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;
        }
        
        M Offline
        M Offline
        mpergand
        wrote on last edited by
        #2

        @Narutoblaze
        try:
        QPushButton:checked{ background-color: rgb(40,40,40)

        NarutoblazeN 1 Reply Last reply
        0
        • M mpergand

          @Narutoblaze
          try:
          QPushButton:checked{ background-color: rgb(40,40,40)

          NarutoblazeN Offline
          NarutoblazeN Offline
          Narutoblaze
          wrote on last edited by Narutoblaze
          #3

          @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.

          Pl45m4P M 2 Replies Last reply
          0
          • NarutoblazeN 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.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #4

            @Narutoblaze

            Add all of your buttons which control the stackedWidget to a QButtonGroup and make it exklusive with setExclusive

            • https://doc.qt.io/qt-6/qbuttongroup.html#exclusive-prop

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            2
            • NarutoblazeN 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.

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #5

              @Narutoblaze
              You have to call setAutoExclusive(true)
              for all the buttons.

              1 Reply Last reply
              0
              • NarutoblazeN Offline
                NarutoblazeN Offline
                Narutoblaze
                wrote on last edited by
                #6

                @Pl45m4 @mpergand thanks for you time it worked perfectly for me

                1 Reply Last reply
                0
                • NarutoblazeN Narutoblaze has marked this topic as solved on
                • NarutoblazeN Narutoblaze has marked this topic as unsolved on
                • NarutoblazeN Narutoblaze has marked this topic as solved on

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved