gpt4 book ai didi

pyqt - 如何在 PyQt5 中获取 QEvent 的字符串名称

转载 作者:行者123 更新时间:2023-12-01 21:34:00 27 4
gpt4 key购买 nike

在 PyQt 下,我正在为 Qt Events 计时,我想用时间写一个人类可读的字符串名称。使用 PySide2 时,只需调用 str() 即可获得字符串名称,但使用 PyQt5 时,它会返回一个作为枚举值的字符串:

# PySide2
>>> str(QEvent.KeyPress)
'PySide2.QtCore.QEvent.Type.KeyPress'

# PyQt5
>>> str(QEvent.KeyPress)
'6'

有没有办法使用 PyQt5 获取字符串名称?我可以发布一个在启动时构建查找表的解决方案,这可行,但想知道是否有直接的方法。

最佳答案

这就是我用来记录发生在我的 QWidget 子类上的事件的方法。刚刚从文档中制作了查找表 https://doc.qt.io/qt-5/qevent.html

def event(self, event: QtCore.QEvent) -> bool:
print(event_lookup[str(event.type())])
return super().event(event)

event_lookup = {"0": "QEvent::None",
"114": "QEvent::ActionAdded",
"113": "QEvent::ActionChanged",
"115": "QEvent::ActionRemoved",
"99": "QEvent::ActivationChange",
"121": "QEvent::ApplicationActivate",
"122": "QEvent::ApplicationDeactivate",
"36": "QEvent::ApplicationFontChange",
"37": "QEvent::ApplicationLayoutDirectionChange",
"38": "QEvent::ApplicationPaletteChange",
"214": "QEvent::ApplicationStateChange",
"35": "QEvent::ApplicationWindowIconChange",
"68": "QEvent::ChildAdded",
"69": "QEvent::ChildPolished",
"71": "QEvent::ChildRemoved",
"40": "QEvent::Clipboard",
"19": "QEvent::Close",
"200": "QEvent::CloseSoftwareInputPanel",
"178": "QEvent::ContentsRectChange",
"82": "QEvent::ContextMenu",
"183": "QEvent::CursorChange",
"52": "QEvent::DeferredDelete",
"60": "QEvent::DragEnter",
"62": "QEvent::DragLeave",
"61": "QEvent::DragMove",
"63": "QEvent::Drop",
"170": "QEvent::DynamicPropertyChange",
"98": "QEvent::EnabledChange",
"10": "QEvent::Enter",
"150": "QEvent::EnterEditFocus",
"124": "QEvent::EnterWhatsThisMode",
"206": "QEvent::Expose",
"116": "QEvent::FileOpen",
"8": "QEvent::FocusIn",
"9": "QEvent::FocusOut",
"23": "QEvent::FocusAboutToChange",
"97": "QEvent::FontChange",
"198": "QEvent::Gesture",
"202": "QEvent::GestureOverride",
"188": "QEvent::GrabKeyboard",
"186": "QEvent::GrabMouse",
"159": "QEvent::GraphicsSceneContextMenu",
"164": "QEvent::GraphicsSceneDragEnter",
"166": "QEvent::GraphicsSceneDragLeave",
"165": "QEvent::GraphicsSceneDragMove",
"167": "QEvent::GraphicsSceneDrop",
"163": "QEvent::GraphicsSceneHelp",
"160": "QEvent::GraphicsSceneHoverEnter",
"162": "QEvent::GraphicsSceneHoverLeave",
"161": "QEvent::GraphicsSceneHoverMove",
"158": "QEvent::GraphicsSceneMouseDoubleClick",
"155": "QEvent::GraphicsSceneMouseMove",
"156": "QEvent::GraphicsSceneMousePress",
"157": "QEvent::GraphicsSceneMouseRelease",
"182": "QEvent::GraphicsSceneMove",
"181": "QEvent::GraphicsSceneResize",
"168": "QEvent::GraphicsSceneWheel",
"18": "QEvent::Hide",
"27": "QEvent::HideToParent",
"127": "QEvent::HoverEnter",
"128": "QEvent::HoverLeave",
"129": "QEvent::HoverMove",
"96": "QEvent::IconDrag",
"101": "QEvent::IconTextChange",
"83": "QEvent::InputMethod",
"207": "QEvent::InputMethodQuery",
"169": "QEvent::KeyboardLayoutChange",
"6": "QEvent::KeyPress",
"7": "QEvent::KeyRelease",
"89": "QEvent::LanguageChange",
"90": "QEvent::LayoutDirectionChange",
"76": "QEvent::LayoutRequest",
"11": "QEvent::Leave",
"151": "QEvent::LeaveEditFocus",
"125": "QEvent::LeaveWhatsThisMode",
"88": "QEvent::LocaleChange",
"176": "QEvent::NonClientAreaMouseButtonDblClick",
"174": "QEvent::NonClientAreaMouseButtonPress",
"175": "QEvent::NonClientAreaMouseButtonRelease",
"173": "QEvent::NonClientAreaMouseMove",
"177": "QEvent::MacSizeChange",
"43": "QEvent::MetaCall",
"102": "QEvent::ModifiedChange",
"4": "QEvent::MouseButtonDblClick",
"2": "QEvent::MouseButtonPress",
"3": "QEvent::MouseButtonRelease",
"5": "QEvent::MouseMove",
"109": "QEvent::MouseTrackingChange",
"13": "QEvent::Move",
"197": "QEvent::NativeGesture",
"208": "QEvent::OrientationChange",
"12": "QEvent::Paint",
"39": "QEvent::PaletteChange",
"131": "QEvent::ParentAboutToChange",
"21": "QEvent::ParentChange",
"212": "QEvent::PlatformPanel",
"217": "QEvent::PlatformSurface",
"75": "QEvent::Polish",
"74": "QEvent::PolishRequest",
"123": "QEvent::QueryWhatsThis",
"106": "QEvent::ReadOnlyChange",
"199": "QEvent::RequestSoftwareInputPanel",
"14": "QEvent::Resize",
"204": "QEvent::ScrollPrepare",
"205": "QEvent::Scroll",
"117": "QEvent::Shortcut",
"51": "QEvent::ShortcutOverride",
"17": "QEvent::Show",
"26": "QEvent::ShowToParent",
"50": "QEvent::SockAct",
"192": "QEvent::StateMachineSignal",
"193": "QEvent::StateMachineWrapped",
"112": "QEvent::StatusTip",
"100": "QEvent::StyleChange",
"87": "QEvent::TabletMove",
"92": "QEvent::TabletPress",
"93": "QEvent::TabletRelease",
"171": "QEvent::TabletEnterProximity",
"172": "QEvent::TabletLeaveProximity",
"219": "QEvent::TabletTrackingChange",
"22": "QEvent::ThreadChange",
"1": "QEvent::Timer",
"120": "QEvent::ToolBarChange",
"110": "QEvent::ToolTip",
"184": "QEvent::ToolTipChange",
"194": "QEvent::TouchBegin",
"209": "QEvent::TouchCancel",
"196": "QEvent::TouchEnd",
"195": "QEvent::TouchUpdate",
"189": "QEvent::UngrabKeyboard",
"187": "QEvent::UngrabMouse",
"78": "QEvent::UpdateLater",
"77": "QEvent::UpdateRequest",
"111": "QEvent::WhatsThis",
"118": "QEvent::WhatsThisClicked",
"31": "QEvent::Wheel",
"132": "QEvent::WinEventAct",
"24": "QEvent::WindowActivate",
"103": "QEvent::WindowBlocked",
"25": "QEvent::WindowDeactivate",
"34": "QEvent::WindowIconChange",
"105": "QEvent::WindowStateChange",
"33": "QEvent::WindowTitleChange",
"104": "QEvent::WindowUnblocked",
"203": "QEvent::WinIdChange",
"126": "QEvent::ZOrderChange", }

关于pyqt - 如何在 PyQt5 中获取 QEvent 的字符串名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62196835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com