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. QScrollArea: Area is not updated while an arrow key is held pressed
Forum Updated to NodeBB v4.3 + New Features

QScrollArea: Area is not updated while an arrow key is held pressed

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 262 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.
  • T Offline
    T Offline
    titan73
    wrote on last edited by titan73
    #1

    While the key is pressed only a scroll bar is updated but not the area. The area is update when the arrow key is released.
    I'd like to change my code to fix that.

    I tried reimplementing keyPressEvent and forcing updating or repainting the viewport at the end like:

    void keyPressEvent(QKeyEvent *event) override {
        int step = 20; // Set your custom scroll step here
    
        switch (event->key()) {
            case Qt::Key_Up:
                verticalScrollBar()->setValue(verticalScrollBar()->value() - step);
                break;
            case Qt::Key_Down:
                verticalScrollBar()->setValue(verticalScrollBar()->value() + step);
                break;
            case Qt::Key_Left:
                horizontalScrollBar()->setValue(horizontalScrollBar()->value() - step);
                break;
            case Qt::Key_Right:
                horizontalScrollBar()->setValue(horizontalScrollBar()->value() + step);
                break;
            default:
                QScrollArea::keyPressEvent(event); // Call base class implementation for other keys
        }
    
        // Solution 1:
        // Force the viewport to update
        viewport()->update();
    
        // Solution 2:
        // Force the viewport to repaint
        viewport()->repaint();
    
        // Solution 3
        // Force the viewport to update
        viewport()->update();
       // Ensure the widget inside the scroll area is updated
       if (widget()) {
             widget()->update();
       }
    

    While the key is held pressed keyPressEvent is called several time but the area is still not updated

    How can I fix that? Is it really necessary to reimplement keyPressEvent?

    I'm developping in Qt 5.

    TIA

    1 Reply Last reply
    0
    • T Offline
      T Offline
      titan73
      wrote on last edited by titan73
      #5

      It seems it's an environment issue not related to the Qt code.
      On Ubuntu 22.04 under Virtual Box => the issue appears
      On RedHat 8.9 under a container with Ubuntu 22.04 => the issue does not appear.
      Thanks
      Let's mark this issue as solved.

      1 Reply Last reply
      0
      • Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by
        #2

        First and foremost: Please update to Qt6, maybe the problem is solved by that.
        Are you sure the code is actually hit? Are the update() calls updating the right widget?

        Software Engineer
        The Qt Company, Oslo

        1 Reply Last reply
        0
        • T Offline
          T Offline
          titan73
          wrote on last edited by
          #3

          The code I try to modify is open source software. The gui code is big and can't be ported easily. I don't know there is a plan to switch to Qt6.
          I added a trace and keyPressEvent is called regularly while the key is held pressed. I did an update on our LayoutScroll which inherits from QScrollArea and also out LayoutViewer which inherits from QWidget.

          The classes are there: https://github.com/The-OpenROAD-Project/OpenROAD/blob/master/src/gui/src/layoutViewer.cpp
          And the class that instantiate them: https://github.com/The-OpenROAD-Project/OpenROAD/blob/master/src/gui/src/layoutTabs.cpp

          JonBJ 1 Reply Last reply
          0
          • T titan73

            The code I try to modify is open source software. The gui code is big and can't be ported easily. I don't know there is a plan to switch to Qt6.
            I added a trace and keyPressEvent is called regularly while the key is held pressed. I did an update on our LayoutScroll which inherits from QScrollArea and also out LayoutViewer which inherits from QWidget.

            The classes are there: https://github.com/The-OpenROAD-Project/OpenROAD/blob/master/src/gui/src/layoutViewer.cpp
            And the class that instantiate them: https://github.com/The-OpenROAD-Project/OpenROAD/blob/master/src/gui/src/layoutTabs.cpp

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #4

            @titan73 I would suggest you produce a minimal, standalone program to illustrate (and play with) if you want help here.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              titan73
              wrote on last edited by titan73
              #5

              It seems it's an environment issue not related to the Qt code.
              On Ubuntu 22.04 under Virtual Box => the issue appears
              On RedHat 8.9 under a container with Ubuntu 22.04 => the issue does not appear.
              Thanks
              Let's mark this issue as solved.

              1 Reply Last reply
              0
              • T titan73 has marked this topic as solved on
              • T titan73 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