Tin mới
This page contains links to some useful code snippets. Longer, more detailed code examples can be found via the Overviews_and_Guides page.
QML callback function: How to pass and execute callback functions with QML.
Threading, Signals and Slots: How to perform work in one thread and use the result in another.
Decoding Japanese Text: The response to a posting on comp.lang.python, asking about decoding text for display in a GUI.
Using GStreamer with PyQt: How to use the GStreamer bindings for Python with PyQt (see Multimedia Resources for more multimedia links).
Using GStreamer with PyQt: How to use the GStreamer bindings for Python with PyQt (see Multimedia Resources for more multimedia links).
Threading, Signals and Slots: How to perform work in one thread and use the result in another. (Qt 4)
PyQt/AutoConnectingSlots: How to have the signals of widgets automatically connected to Python defined slots.
Handling Qt's internal item MIME type
Handling Qt's internal item MIME type: How to implement a drop handler in a model to handle items dragged from standard models.
Handling an internal Qt MIME type
Handling an internal Qt MIME type: How to handle the internal MIME type used for drag and drop between item views.
Binding widget properties to Python variables
Binding widget properties to Python variables: Using Python's property system to access Qt properties and bind them to variables.
Making non-clickable widgets clickable
Making non-clickable widgets clickable: How to misuse event filters to add clicked() signals to widgets.
Undo and redo with line edits: An incomplete example showing basic undo/redo handling.
Using a signal mapper: How to associate values with signals from many widgets and use one slot to handle them all.
Sending Python values with signals and slots
Sending Python values with signals and slots: How to communicate Python values via Qt's signals and slots mechanism.
Using a translation of Qt: How to display standard dialogs and messages in your local language.
Getting the version numbers of Qt, SIP and PyQt
Getting the version numbers of Qt, SIP and PyQt: How to obtain the version information for the Qt-related modules you are using.
Writing a client for a zeromq service
Writing a client for a zeromq service: How to access a zeromq service while keeping the GUI responsive.
Drawing highlighted rows in a calendar widget
Drawing highlighted rows in a calendar widget: How to highlight the current week in a QCalendarWidget subclass.
Windows with gradient backgrounds
Windows with gradient backgrounds: How to change the background colour of a window to use a gradient instead of the standard colour in the palette.
Fading Between Widgets: How to create a stacked widget that fades between widgets on different pages.
Fading and unfading a widget with a delay
Fading and unfading a widget with a delay: How to produce a simple fade-unfade animation.
Painting and clipping demonstration
Painting and clipping demonstration: A demonstration showing how to clip what a painter draws on a widget.
Clipping SVG output: How to clip Scalable Vector Graphics (SVG) output when drawing with QPainter.
GraphicsView_-_SimpleAnimation
GraphicsView_-_SimpleAnimation: How to construct a very simple animation using QGraphicsView, QGraphicsItem, QGraphicsItemAnimation and QTimeLine. (Qt4)
Python syntax highlighting: How to add syntax highlighting to a QPlainTextEdit widget. (Qt4)
Painting an overlay on an image
Painting an overlay on an image: How to paint one image onto another.
Movie splash screen: How to paint a movie on a splash screen instead of a static image.
Extend Two QPixmap: How to paint merge two QPixmaps into one QPixmap.
Widgets in a layout: How to create widgets and put them in a layout.
Show an image using a label: How to display an image.
A full widget waiting indicator
A full widget waiting indicator: How to draw a busy/waiting indicator over an entire widget.
Handling context menus: The different ways you can handle context menus.
Five minute steps in a QTimeEdit
Five minute steps in a QTimeEdit: Customise the behaviour of QTimeEdit by subclassing.
Customising tab bars: How to change the size allocated to tabs in tab bars and tab widgets.
Customising a tab to contain a menu
Customising a tab to contain a menu: How to put a menu button in a tab bar.
Adding auto-completion to a QLineEdit
Adding auto-completion to a QLineEdit: How to use a QStringListModel to provide data for auto-completion.
Adding tab-completion to a QLineEdit
Adding tab-completion to a QLineEdit: How to handle key events to enable tab-completion.
Adding custom signals to a simple painted widget
Adding custom signals to a simple painted widget: How to declare and use custom signals.
Creating a widget with a fixed aspect ratio
Creating a widget with a fixed aspect ratio: How to ensure that a widget keeps a certain aspect ratio when it is resized.
Adding a background image to an MDI area
Adding a background image to an MDI area: How to display a non-tiled image in the background of an MDI area widget.
Selecting a region of a widget
Selecting a region of a widget: How to use a QRubberBand to select part of a widget.
Distinguishing between click and double click
Distinguishing between click and double click: How to handle a double click without acting on the first click.
Using a different view with QComboBox
Using a different view with QComboBox: How to replace the standard view used for a combo box's pop-up menu.
Sorting numbers in columns: How to sort a table by the numbers in a given column.
Animated items using delegates
Animated items using delegates: How to animate items in a list view, using a custom delegate, timer events and a signal.
Animated items using delegates and movies
Animated items using delegates and movies: How to animate items in a list view - an improved version of the previous example.
Adding items to a list widget: How to add items to a QListWidget instance.
A custom Python class-based 1D model
A custom Python class-based 1D model: A drag and drop-enabled model which holds Python objects.
Reading selections from a selection model
Reading selections from a selection model: How to read selections and update an underlying model.