PySide

From Bauman National Library
This page was last modified on 8 June 2016, at 19:31.
PySide
File:Pyside.png
Developer Qt Project
First appeared 18 August 2009; 13 years ago (2009-08-18)[1]
Stable release 1.2.4 / 14 October 2015; 7 years ago (2015-10-14)
Implementation language Python
OS Cross-platformTemplate:Fix/category[which?]]]
License LGPL
Website www.pyside.org

Introduction

PySide is an open source software project providing Python bindings for the Qt framework. Qt is a cross-platform application and UI framework, allowing the developers to write applications once and deploy them across many operating systems without rewriting the source code, while Python is a modern, dynamic programming language with a vivid developer community. Combining the power of Qt and Python, PySide provides the wealth of Qt framework for developers writing software in Python and presents a first-class rapid application development platform available on all major operating systems.

PySide Hello World script

This is a very simple "Hello World" script for PySide. Simply copy&paste it into a file, and launch it. For additional information on the classes used, see the PySide reference documentation at http://www.pyside.org/docs/pyside/

#!/usr/bin/python
 
import sys
 
import PySide
from PySide.QtGui import QApplication
from PySide.QtGui import QMessageBox
 
# Create the application object
app = QApplication(sys.argv)
 
# Create a simple dialog box
msgBox = QMessageBox()
msgBox.setText("Hello World - using PySide version " + PySide.__version__)
msgBox.exec_()

Differences Between PySide and PyQt

API differences

  • Different import name (PySide instead of PyQt4)

PySide uses a different library name than PyQt. Instead of typing:

from PyQt4.QtCore import *

or

import PyQt4.QtCore

you have to do the following:

from PySide.QtCore import *

or

import PySide.QtCore
  • New-style signals and slots use slightly different syntax (PSEP 100)

PyQt unfortunately uses an implementation-specific naming scheme for its new-style signal and slot classes:

# Define a new signal called 'trigger' that has no arguments.
trigger = QtCore.pyqtSignal()

As described in PSEP 100, use QtCore.Signal() and QtCore.Slot() instead. If you want to modify your PyQt code to use the PySide naming scheme, that can be done using a simple definition:

QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
.

.

  • Declaring Qt Properties is done using a slightly different syntax (PSEP 103)

As with the signal/slot syntax change above, declaring Qt Properties is done using QtCore. Property instead of QtCore.pyqtProperty (see PSEP 103).

  • Tool names different

PySide uses different names for the tools scripts:

pyuic4 -> pyside-uic
pyrcc4-> pyside-rcc
pylupdate4 -> pyside-lupdate

Property Names

PySide uses connect and event in the QObject. Do not use these for anything in your code, and when moving code from PyQt look for any that exist. QThreads In PySide you should .wait() on a thread after calling .stop() if you are quitting the application. Otherwise you may receive

QThread: Destroyed while thread is still running Segmentation fault

Differences in the functionality of the bindings Bindings for functions deprecated before Qt 4.5 are not generated Bindings for functions deprecated before Qt 4.5 are not generated in PySide. If a function is not present in PySide, check the Qt Online Reference Documentation and see whether the function has been deprecated and what to use instead. Example bug: bug 359 For example, this affects functions such as QColor.dark() and QColor.light(), instead of which QColor.darker() and QColor.lighter() need to be used. sender() method returns None when used within a partial or a lambda If a lambda is used as a slot, sender() cannot be used to acquire the object that emitted the signal. This works in PyQt, but their implementation behaves incorrectly in certain situations. See bug 344 for details. When inheriting classes, parent class constructors need to be always called PyQt in some cases allows code such as:

class Window(QtGui.QWidget):
 def ''init''(self, parent=None):
 super(QtGui.QWidget, self).''init''(parent)

in which the direct parent class constructor is not called. PySide expects you to do the right thing:

class Window(QtGui.QWidget):
 def ''init''(self, parent=None):
 super(Window, self).''init''(parent)

Old style signals need use of parentheses PyQt allows the use of short-circuit signals without parentheses such as:

self.emit(SIGNAL ('text_changed_cb'), text)

Since this is an old and deprecated feature, and the effort to fix this is not worth it, we decided to not implement it. In PySide code you need to use something like:

self.emit(SIGNAL ('text_changed_cb(QString)'), text)

You can check the complete discussion on bug #314 Only signals without arguments can be auto connected on constructor. If you use:

action = QtGui.QAction(None, triggered=handler)

The triggered() signal will be connected to the slot handler instead of the triggered(bool) signal.

Links

  • PySide has been released, August 18th, 2009 – PySide – Python for Qt. Template:Wayback