[PyQt] pyuic4 vs uic Module
Kyle Altendorf
sda at fstab.net
Wed Aug 1 22:24:23 BST 2018
On August 1, 2018 5:08:48 PM EDT, Christopher Probst <christop.probst at gmail.com> wrote:
>Helllo everybody,
>
>Is there any best practice suggestion as to how to interact with the Qt
>ui
>files? Is it better to load them dynamically using the uic module with
>the
>load uic.loadUi method?
>
>Or is it recommended to compile the ui files into python code using
>pyuic4?
I'm not sure any caveats between 4 vs 5 but I much prefer loading at run time. Here's what I'm tending towards now.
https://github.com/altendky/basicpyqt5example/blob/e08e75d16819fddc0514c513f43fa5148e59722c/src/basicpyqt5example/mainwindow.py#L37
Ui, UiBase = PyQt5.uic.loadUiType(
pathlib.Path(__file__).parents[0] / 'mainwindow.ui',
)
class MainWindow(UiBase):
def __init__(self, parent=None):
super().__init__(parent) self.ui = Ui()
self.ui.setupUi(self)
The one caveat that I'm aware of is the lack of a .py file for an IDE to parse for help completing names. I'll note that there is a call in uic for compiling without having to run pyuic from the command line so some hybrid might make sense.
Cheers,
-kyle
More information about the PyQt
mailing list