Results 1 to 2 of 2

Thread: Vertical scrolling with the mouse wheel in QGraphicsView in versions 5.15.1 and 6.6.1

  1. #1
    Join Date
    Oct 2020
    Posts
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Vertical scrolling with the mouse wheel in QGraphicsView in versions 5.15.1 and 6.6.1

    In version 5.15.1, if the mouse cursor is over a widget (as in the example below - QTextEdit), there is scrolling for the entire QGraphicsView. In version 6.6.1, scrolling only occurs when the mouse cursor is not over QTextEdit. Is it possible to achieve the behavior that was present in version 5.15.1 ?

    Qt Code:
    1. #include <QGraphicsScene>
    2. #include <QGraphicsView>
    3. #include <QVBoxLayout>
    4. #include <QTextEdit>
    5. #include <QWidget>
    6. #include <QGraphicsProxyWidget>
    7.  
    8. MainWindow::MainWindow(QWidget *parent)
    9. : QMainWindow(parent)
    10. , ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13.  
    14. QGraphicsScene*scene=new QGraphicsScene(1,1,109,1199);
    15.  
    16. QGraphicsView* graphicsView = new QGraphicsView(scene);
    17.  
    18. setCentralWidget(graphicsView);
    19.  
    20. graphicsView->setFrameShape(QFrame::NoFrame);
    21.  
    22. QTextEdit* textEdit = new QTextEdit();
    23.  
    24. QGraphicsProxyWidget* proxyWidget = new QGraphicsProxyWidget();
    25. proxyWidget->setWidget(textEdit);
    26.  
    27. scene->addItem(proxyWidget);
    28.  
    29. textEdit->move(-100,500);
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by VVS; 26th January 2024 at 11:11.

  2. #2
    Join Date
    May 2025
    Posts
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: Vertical scrolling with the mouse wheel in QGraphicsView in versions 5.15.1 and 6

    Quote Originally Posted by VVS View Post
    In version 5.15.1, if the mouse cursor is over a widget (as in the example below - QTextEdit), there is scrolling for the entire QGraphicsView. In version 6.6.1, scrolling only occurs when the mouse cursor is not over QTextEdit. Is it possible to achieve the behavior that was present in version 5.15.1 ?

    Qt Code:
    1. #include <QGraphicsScene>
    2. #include <QGraphicsView>
    3. #include <QVBoxLayout>
    4. #include <QTextEdit>
    5. #include <QWidget>
    6. #include <QGraphicsProxyWidget>
    7.  
    8. MainWindow::MainWindow(QWidget *parent)
    9. : QMainWindow(parent)
    10. , ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13.  
    14. QGraphicsScene*scene=new QGraphicsScene(1,1,109,1199);
    15.  
    16. QGraphicsView* graphicsView = new QGraphicsView(scene);
    17.  
    18. setCentralWidget(graphicsView);
    19.  
    20. graphicsView->setFrameShape(QFrame::NoFrame);
    21.  
    22. QTextEdit* textEdit = new QTextEdit();
    23.  
    24. QGraphicsProxyWidget* proxyWidget = new QGraphicsProxyWidget();
    25. proxyWidget->setWidget(textEdit);
    26.  
    27. scene->addItem(proxyWidget);
    28.  
    29. textEdit->move(-100,500);
    30. }
    To copy to clipboard, switch view to plain text mode 
    Hello,
    I had something similar.
    What I did was define a new class daughter of QTextEdit, make sure that its parent is the QGraphicView, and redefine wheelEvent so that it calls the parent's wheelEvent.
    In python :
    Qt Code:
    1. from PySide6.QtWidgets import QTextEdit
    2.  
    3. class NewTextEdit(QTextEdit):
    4. def __init__(self, parent):
    5. super().__init__(parent)
    6. self.parent = parent
    7.  
    8. def wheelEvent(self, event):
    9. self.parent.wheelEvent(event)
    10. return True
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsView and Scrolling
    By validator in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2017, 00:27
  2. QGraphicsView Scrolling
    By tvj4218 in forum Newbie
    Replies: 1
    Last Post: 7th March 2017, 07:06
  3. Scrolling QGraphicsView and QGraphicsScene
    By freely in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2013, 13:37
  4. Replies: 0
    Last Post: 26th November 2009, 15:49
  5. Custom scrolling of QGraphicsView
    By hb in forum Qt Programming
    Replies: 0
    Last Post: 12th August 2008, 10:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.