Is there a tutorial specifically for PyQt5?

I am looking for a PyQt5 tutorial. It's pretty hard to start developing a GUI using Python for the first time without a tutorial.

So far I have found some PyQt4 tutorials, and since something has changed from Qt4 to Qt5, for example, the fact SIGNAL and SLOT no longer supported in Qt5, it would be nice to have special manuals for PyQt5.

Can someone please provide a tutorial on how to start GUI development using PyQt5?

+48
python user-interface qt5 pyqt5
Jan 08 '14 at 12:51 on
source share
3 answers

As my journeys into the depths of PyQt5 continue, I will continue to update this answer with some of the more brilliant treasures that I find.

Having said that, I am now taking a โ€œrough draftโ€ with a quick introduction to PyQt5. I will also talk about useful resources. I am new to this structure, and I will talk about how I consider it a good strategy to use it, because I believe that this strategy. There are probably other good strategies, so if someone has something to add, please leave a comment. This is a very big job.




Strategy

I learned a lot from the example code, as suggested in another answer, but something that the examples do not help is the deep magic of PyQt5. Frames with a lot of magic in them (PyQt5, Django, SQLAlchemy, ...) are great, because a lot of hard work is distracted from you. On the other hand, itโ€™s not always clear what the hell is going on, or what you should do about it.

Fortunately, it looks like we have options:

  • QtDesigner : In those days when your keyboard lights up, a graphical GUI-Builder is called in the installation package. When you see the code that it produces (perhaps only in the community version?), You will understand why it may not be the panacea that seems.

  • QML : Another candidate for a panacea: declarative graphic building from formatted JSON. Yum.

  • Qt Quick : The foundation for QML. At this point, it may seem painfully easy, but so far this does not need to be pulled. It seems like it comes down to exploring it manually.

  • Presentation Model Framework (1) : Model-View (not MVC) separates code that deals with presentation / interaction with data management code in order to provide modularity.

Coding in PyQt5 is greatly simplified with a set of classes that implement the Model-View design pattern. Model-View is an evolution of Model-View-Controller (MVC) in which the controller is reunited with the view. They seem strange friends, but most of the program logic is either related to the user or to the data: it seems to have a certain meaning, at least at the level of the stratosphere.

From the eyes of a bird:

Architecture (s)

Model-View-Controller

This widely used design template divides the application into 3 layers:

  • Model ~> Encapsulates data. Notifies View and Controller of any changes to the underlying data. This leads to an updated display of the output or available commands, respectively.
  • View ~> Displays the corresponding model output for the user.
  • Controller ~> Encapsulates user interaction and notifies the model and presentation of the relevant events.

Model view

  • Graphical Presentation Environment (1) ~> Represents everything (including embedded QWidgets, etc.) inside a QGraphicsScene as a QGraphicsItem (or its derivatives), including proxy classes for embedding widgets. Elements are supposedly highly optimized, and OpenGL support integration is single-line, which is nice.

This design template places the controller in the view. Thus, the view is able to fully handle user interaction. In specific terms, these are signal and slot mechanisms.

User Interaction Management

Callbacks

Signals and Slots

..... ** Sorry, but I have to sign now. I will be back to continue adding to this. **

Case Study (s)

For example, you can take a tree view from the itemviews/editabletreemodel example and then swap it in the file system model ( QFileSystemModel ) from the itemviews/dirview , and you have a full (working) view of your directory tree. Pretty dull.

So, you would take the code from the editabletreemodel example:

 headers = ("Title", "Description") file = QFile(':/default.txt') file.open(QIODevice.ReadOnly) model = TreeModel(headers, file.readAll()) file.close() self.view.setModel(model) 

... and swapping in a model from dirview:

 model = QFileSystemModel() model.setRootPath('') self.view.setModel(model) 

... and it just works. Amazing

The next step (in my case) (* I think) implements a user model in which I will use several views at the same time, but I do not know if this is suitable for your use case.

Resources

Here are some gems I've found on my travels. Hope they help you.

This is a Model-View tutorial for Qt5. (1) This is a very detailed document from Qt5 white papers. A lot of useful documentation can be found on the Qt5 website. Keep in mind that this is for Qt5 (C ++ library), but the difference is trivial to read (and the official PyQt5 docs indicate there anyway).

This PDF provides a quick, high-level approach to the PyQt4 Model-View framework. Note that this is for PyQt4 (not PyQt5), but actually it is for Python (unlike C ++), and I taught me very quickly.

I am just starting to play with graphical representation and find this Framework Graphical Tutorial very useful. This is the same view used in the qtdemo code qtdemo to generate some gliding effects. I will update this a bit.

This is a complete list of all Qt5 modules.

This is a complete list of all Qt5 classes.

This is a complete list of all the features of the Qt5 API.

As katsh said in another answer to the answer, here is a link to sample code for PyQt5.2.1 on GitHub

In addition, a copy of the sample code is supplied with your distribution and can be found at:

 %PYTHON_HOME%\Lib\site-packages\PyQt5\examples 

If you use PyDev (Eclipse), you can run the examples by simply right-clicking the example of the main module file in PyDev Package Explorer or Navigator =:> Run As =:> Python Run

Best of my (not so) humble opinions:

 %PYTHON_HOME%\Lib\site-packages\PyQt5\examples\qtdemo\qtdemo.py 

Among my current projects, I'm in the process of reverse engineering. If you check this, you will understand why. To be continued.;)

Enjoy it!

+53
Jul 10 '14 at 9:32
source share

Have you been looking for PyQt5 tutorials for some time? Do not look further! You will not find much on the Internet.

Not really textbooks, but rather simple explanatory basic scripts along the following path:

/ python / lib / site-packages / PyQt5 / examples

you will find 100 examples in folders 30 from beginner to advanced, covering the main windows, menus, tabs, layouts, network, OpenGL, etc.

+26
Jan 26 '14 at 2:57
source share
+8
Jan 24 '14 at 7:45
source share



All Articles