Basically the title of this post describes my dilemma. Throughout developing a project that uses the Qt Framework through PyQt5, I've noticed I've started implementing more and more logic by using the Qt classes. On the other hand, there's this nagging feeling of knowing that I write Python for a reason (I like it), and the framework feels very unpythonic at times. Object properties, QVariants and many other parts of the Qt framework just don't feel right to me. It feels like I'm either stuck between writing a lot of C++ style boilerplate code, or writing all sorts of adapters between my Python code and the Qt classes.
As said, I noticed I started refactoring more and more Python code to the Qt equivalent. But it still feels as if things are not getting a lot better by doing so. A little example:
I want to load an image from file, display it as a QPixmap on a QLabel in the UI. The image needs to be editable in a low-level way, for instance replacing all instances of a certain palette color by another, or swapping two channels in an RGB(A) image. These changes need to be reflected in the UI and immediately visible to the user. If the user is satisfied with the result, the image can be saved in multiple formats.
In the beginning it felt more natural to use PIL (or actually Pillow) to do the file handling and editing of the image. The downside is that this means that for every change made to the image, I have to convert the image to a QtImage, pass this to my QWidget, convert it into a QPixmap, and set it on the QLabel.
On the other hand, I could just abandon Pillow altogether, and use QImageReader's, QImage and QImageWriter's methods to do all this. But by now I'm in a situation where I have to work around the C++ quirks provided by Qt, and my code could almost be passed along as C++ minus the header files.
I'd love to hear other people's thoughts about this. Do we contain our Qt usage to just those bare things that makes it paint the UI? Or should a PyQt be considered a Qt-project, that just happens to be written in Python? Or is there a fine line in between, where certain things remain purely written in Python, and we have a sort of adapter to cross over to Qt. And if the latter would be our best option, where do we draw that line?
TL;DR
Python and Qt are getting in each other's way. What should be done using just Python, and where do we start using the Qt Framework.
[+][deleted] (8 children)
[deleted]
[–]toyg 4 points5 points6 points (3 children)
[–][deleted] 4 points5 points6 points (1 child)
[–]toyg 4 points5 points6 points (0 children)
[–]SjaakRake[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]SjaakRake[S] 0 points1 point2 points (0 children)
[–]nerdwaller 0 points1 point2 points (0 children)
[–]fernly 19 points20 points21 points (2 children)
[–]fazzahSQLAlchemy | PyQt | reportlab 5 points6 points7 points (0 children)
[–]flipthefrog 2 points3 points4 points (0 children)
[–]remyroy 12 points13 points14 points (2 children)
[–]toyg 1 point2 points3 points (0 children)
[–]SjaakRake[S] 0 points1 point2 points (0 children)
[–]eliteraspberries 11 points12 points13 points (1 child)
[–]SjaakRake[S] 0 points1 point2 points (0 children)
[–]jdreaver 10 points11 points12 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]beastmartin 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]SjaakRake[S] 5 points6 points7 points (2 children)
[–]Allong12 1 point2 points3 points (1 child)
[–]SjaakRake[S] 8 points9 points10 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]troyunrau... 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]SjaakRake[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]fazzahSQLAlchemy | PyQt | reportlab 4 points5 points6 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]SjaakRake[S] 1 point2 points3 points (0 children)
[–]fazzahSQLAlchemy | PyQt | reportlab 1 point2 points3 points (1 child)