英文:
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
以下是要翻译的内容:
- 学会与之共处。
- 切换到 PySide6。
- 再次尝试学会与之共处。
- 成为一名僧侣,永远不再触碰计算机。
- 将枚举分配给一个简短的变量:
cm = QCompleter.CompletionMode
。
英文:
A couple of solutions ranked to my personal preference:
- Learn to live with it.
- Switch to PySide6.
- Try to learn to live with it again.
- Become a monk and never touch a computer again.
- Assign the enum to a short named variable:
cm = QCompleter.CompletionMode
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论