Skip to content

Support Qt6#206

Open
ahcorde wants to merge 1 commit intorollingfrom
ahcorde/rolling/support_qt6
Open

Support Qt6#206
ahcorde wants to merge 1 commit intorollingfrom
ahcorde/rolling/support_qt6

Conversation

@ahcorde
Copy link
Copy Markdown
Contributor

@ahcorde ahcorde commented Feb 16, 2026

No description provided.

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde ahcorde self-assigned this Feb 16, 2026
@ahcorde ahcorde mentioned this pull request Feb 16, 2026
def on_key_press(self, event):
key = event.key()
if key == Qt.Key_Space:
if key == Qt.Key.Key_Space:
Copy link
Copy Markdown

@asymingt asymingt Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize you didn't write this code originally.

However, in the worst case you're going to evaluate N conditionals to get the desired action. Consider doing this in O(1) with a dictionary of function pointers declared on init, which IMO is more readable:

 def __init__(self, context, publish_clock):
    ...
    self.KEY_TO_ACTION = {
        Qt.Key.Key_Space: self._timeline.toggle_play,
        Qt.Key.Key_Home: self._timeline.navigate_start,
        Qt.Key.Key_End: self._handle_end_clicked,
        Qt.Key.Key_Plus self._handle_faster_clicked,
        Qt.Key.Key_Equal: self._handle_faster_clicked,
        Qt.Key.Key_Minus: self._handle_slower_clicked,
        Qt.Key.Key_Left: self._timeline.translate_timeline_left,
        Qt.Key.Key_Right: self._timeline.translate_timeline_right,
        Qt.Key.Key_Up self._handle_zoom_in_clicked,
        Qt.Key.Key_PageUp: self._handle_zoom_in_clicked,
        Qt.Key.Key_Down: self._handle_zoom_out_clicked,
        Qt.Key.Key_PageDown: self._handle_zoom_out_clicked
    }

Then you just call this here:

self.KEY_TO_ACTION.get(event.key(), lambda: None)()

from python_qt_binding import QT_BINDING_VERSION
from python_qt_binding.QtGui import QIcon
from python_qt_binding.QtWidgets import QAction, QToolBar
if Version(QT_BINDING_VERSION) > Version('6.0.0'):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider try - catch with ImportErrror

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants