Issue
I'm starting to use PyQt in some projects and I'm running into a stylistic dilemma. PyQt's functions use camel case, but PEP8, which I prefer to follow, says to use underscores and all lowercase for function names.
So on the one hand, I can continue to follow PEP8, meaning that my code will have mixed functions calls to camel case and underscore functions, and even my classes will have mixed function names, since I'll need to be overloading functions like mousePressEvent. Or, I can break PEP8 and adopt camel case for all my function names in the name of consistency.
I realize this is subjective and it's really just what I personally prefer, but I like to hear from others about what they do and why they chose to do it that way.
Solution
In december 2020, with the release of Qt 6.0, the Qt for Python 6 / PySide6 (the official Python bindings for Qt) was also released, introducing a new option called __feature__
. With this option you can have Qt objects with PEP8-compliant snake case methods and true properties.
Old style:
table = QTableWidget()
table.setColumnCount(2)
button = QPushButton("Add")
button.setEnabled(False)
layout = QVBoxLayout()
layout.addWidget(table)
layout.addWidget(button)
New PySide6 style:
from __feature__ import snake_case, true_property
table = QTableWidget()
table.column_count = 2
button = QPushButton("Add")
button.enabled = False
layout = QVBoxLayout()
layout.add_widget(table)
layout.add_widget(button)
Answered By - Jeyekomon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.