<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
code
{mso-style-priority:99;
font-family:"Courier New";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">I have 200 objects on the MyView that is derived from the QGraphicsView. I use the mouse wheel to scroll vertically, everything is nice and smooth. I think that is the Qt default implementation.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I implement the Shift + wheel to scroll horizontally, and the horizontal scroll bar jumps a huge step on a single wheel event - 10 times bigger than that on the vertical scroll bar.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Basically, the same wheel event drives the horizontal scroll bar 10 times farther than the vertical scroll bar.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">How to slow down the horizontal scroll bar?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Well, I tried to reduce the original event's angleDelta value like this event.angleDelta()/10 to generate a new wheel event and use the new event to drive the horizontal scroll bar. That works but seems to be too complicated.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I also notice it is the Shift modifier that affects the horizontal scroll bar behavior. If I do self.horizontalScrollBar().wheelEvent(event) without the Shift modifier, the horizontal bar scrolling is 10 times slower. That is weird. Why
does pressing Shift change the horizontal scrolling behavior?!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Please help. Here is the self-contained program:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">#----------------------<o:p></o:p></p>
<p class="MsoNormal">import sys<o:p></o:p></p>
<p class="MsoNormal">from PyQt5.QtWidgets import QGraphicsScene, QGraphicsView, QGraphicsTextItem, QApplication<o:p></o:p></p>
<p class="MsoNormal">from PyQt5.QtCore import Qt<o:p></o:p></p>
<p class="MsoNormal">from PyQt5.QtGui import QWheelEvent<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">class MyView(QGraphicsView):<o:p></o:p></p>
<p class="MsoNormal"> def wheelEvent(self, event: QWheelEvent):<o:p></o:p></p>
<p class="MsoNormal"> if event.modifiers() == Qt.ShiftModifier:<o:p></o:p></p>
<p class="MsoNormal"> self.horizontalScrollBar().wheelEvent(event)<o:p></o:p></p>
<p class="MsoNormal"> else:<o:p></o:p></p>
<p class="MsoNormal"> self.verticalScrollBar().wheelEvent(event)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">if __name__ == '__main__':<o:p></o:p></p>
<p class="MsoNormal"> <span lang="FR">app = QApplication(sys.argv)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR"> scene = QGraphicsScene()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR"> </span>view = MyView(scene)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> # Generate 200 objects, 100 on x and 100 on y.<o:p></o:p></p>
<p class="MsoNormal"> for i in range(100):<o:p></o:p></p>
<p class="MsoNormal"> obj_on_x = QGraphicsTextItem("X" + str(i))<o:p></o:p></p>
<p class="MsoNormal"> obj_on_x.setX(i * 100)<o:p></o:p></p>
<p class="MsoNormal"> scene.addItem(obj_on_x)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> <span lang="FR">obj_on_y = QGraphicsTextItem("Y" + str(i))<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR"> </span>obj_on_y.setY(i * 100)<o:p></o:p></p>
<p class="MsoNormal"> scene.addItem(obj_on_y)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> view.show()<o:p></o:p></p>
<p class="MsoNormal"> sys.exit(app.exec_())<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>