如何避免在PyQt6中使用过长的枚举常量

huangapple go评论59阅读模式
英文:

How to avoid long enum constants in PyQt6

问题

最近,我开始了一个新的PyQt项目。多年来,我一直在使用PyQt5,但为了保持现代化,我想切换到PyQt6。

结果发现在PyQt6中,枚举常量变得非常冗长。下面是一个具体的例子:

PyQt5

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QCompleter

completer = QCompleter()
completer.setCaseSensitivity(False)
completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)

PyQt6

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QCompleter

completer = QCompleter()
completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
completer.setCompletionMode(QCompleter.CompletionMode.UnfilteredPopupCompletion)

现在,常量的输入变得非常冗长。是否有人提出了一种设计模式来克服这种不便?

英文:

Recently I started a new PyQt project. I've been using PyQt5 for years, but to stay modern I thought I'd switch to PyQt6.

Come to find out that enum constants got really verbose in PyQt6. How about a concrete example?

PyQt5

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QCompleter

completer = QCompleter()
completer.setCaseSensitivity(False)
completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)

PyQt6

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QCompleter

completer = QCompleter()
completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
completer.setCompletionMode(QCompleter.CompletionMode.UnfilteredPopupCompletion)

Constants are now getting ridiculously long to type. Has anybody come up with a design pattern to overcome this inconvenience?

答案1

得分: 2

以下是要翻译的内容:

  1. 学会与之共处。
  2. 切换到 PySide6。
  3. 再次尝试学会与之共处。
  4. 成为一名僧侣,永远不再触碰计算机。
  5. 将枚举分配给一个简短的变量:cm = QCompleter.CompletionMode
英文:

A couple of solutions ranked to my personal preference:

  1. Learn to live with it.
  2. Switch to PySide6.
  3. Try to learn to live with it again.
  4. Become a monk and never touch a computer again.
  5. Assign the enum to a short named variable: cm = QCompleter.CompletionMode.

huangapple
  • 本文由 发表于 2023年5月11日 05:07:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76222566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定