Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When coding in PyQt (or PySide), should I use Python functions or the equivalent Qt functions?

When writing code using PyQt or PySide, sometimes the equivalent function is available in both Qt and Python (e.g., QDir.exists in Qt vs os.path.exists in Python). In these cases, is there an established practice for which language to use?

I am wondering if issues of speed, refactoring, etc. might be relevant to the decision.

Thanks.

like image 226
Lozzer Avatar asked Nov 04 '22 20:11

Lozzer


1 Answers

As I understand, many of those Qt functions were put in for cross-platform compatibility, and others to integrate with Qt. However, Python already includes cross-platform functions, so I would favor Python ones when possible since they're

  • More familiar to Python programmers
  • Doesn't make you so dependent on Qt
  • Fits in with Python's idioms

However, you may have to use Qt's functions since they integrate with Qt and/or they provide functionality that Python doesn't.

This has been discussed for other languages, e.g. C++: Qt: Qt classes vs. standard C++

Really, it depends on whether you want to write a Qt application or a Python application.

like image 137
li.davidm Avatar answered Nov 06 '22 22:11

li.davidm