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. Problem in getting focus?
Qt 6.11 is out! See what's new in the release blog

Problem in getting focus?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 5.1k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    In my program i am reimplementing key press event but it is not getting called in pressing the arrow key
    @void slider::keyPressEvent (QKeyEvent *event)
    {
    qDebug ()<<"keypress";
    if (slider_mode) {
    if (event->key () == Qt::Key_Left) {
    event->accept ();

            thumb_pos_groove = thumb_pos_groove - 1;
            calcNewValue ();
            emit sliderMoved (value_pos_hori);
            this->repaint ();
        } else if (event->key () == Qt::Key_Right){
            event->accept ();
            thumb_pos_groove = thumb_pos_groove + 1;
            calcNewValue ();
            emit sliderMoved (value_pos_hori);
            this->repaint ();
        }
    } else {
        if (event->key () == Qt::Key_Up) {
            event->accept ();
            thumb_pos_groove = thumb_pos_groove - 1;
            calcNewValue ();
            //emit sliderMoved (value_pos_verti);
            this->repaint ();
        } else if (event->key () == Qt::Key_Down){
            event->accept ();
            thumb_pos_groove = thumb_pos_groove + 1;
            calcNewValue ();
            //emit sliderMoved (value_pos_verti);
            this->repaint ();
        }
    }
    

    }@
    . I am not able to find what is the problem .

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      This could be tricky, but could it be the slider_mode boolean not set?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        no because i am always setting slider mode .

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          [quote author="pratik041" date="1321346642"]no because i am always setting slider mode .[/quote]

          Apologize me for insisting, but setting slider_mode will result in avoiding the execution of the key.up/down handling. So if you are seeing the debug message but nothing happens when you push up/down then it is the boolean flag interfering with your code. Otherwise does the code for the up key work? Could you check exactly what key event is generated when you push the down key?

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            i am not seeing debug message itself.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Things I would check:

              is there an event filter installed somewhere?

              is the widget getting the focus properly?

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                no event filter is installed
                I am making a custom slider and using arrow key for that only. I think the slider is not getting focus because while pressing up and down arrow key after clicking slider the spin box value is changing not slider.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  If I get it right, the problem seems to be that the spinbox has the focus and not the slider. If that is the case, my first thoughts will be to either

                  • give back the focus to the slider after any change in the spinbox
                  • propagate the keypress event from the spin box to the slider (so implement a keyevent listener in the spinbox too and send the event to the slider).

                  But in both cases, please note that any widget in the window will have to do the same, or your changes will be vanished from adding new widgets. So, if this is the problem, I suggest to implement the event listener in the main widget and propagate it to the slider.
                  Someone could have better suggestions.

                  1 Reply Last reply
                  0

                  • Login

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