Note that we only change the internal timeZoneOffset attribute, emit the timeZoneChanged() signal and update the widget if the new value is different to the old one. Self.emit(QtCore.SIGNAL("timeZoneChanged(int)"), value) The setTimeZone() method is also defined to be a slot - we show this in the next section. The getter just returns the internal time zone value. The timeZone property is implemented using the getTimeZone() getter method, the setTimeZone() setter method, and the resetTimeZone() method. The timeZoneChanged() signal is emitted whenever the user, or another component, changes the time zone property. The updateTime() method simply emits the current time every second when a time out occurs. Self.emit(QtCore.SIGNAL("timeChanged(QTime)"), ()) nnect(timer, QtCore.SIGNAL("timeout()"), self.updateTime) nnect(timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("update()")) We change the class's _init_() method to define an attribute to hold the time zone and, as well as connecting the timer to the widget's update() slot, we also connect it to the newly added updateTime() method. ![]() Signals that are declared in this way are emitted in the same way as any other signal. The variable must refer to a sequence of strings - we could have used a list instead of a tuple, for example. We use the _pyqtSignals_ class variable to define two signals that are used to inform other components of changes to the clock's time and time zone. _pyqtSignals_ = ("timeChanged(QTime)", "timeZoneChanged(int)") Normally, this isn't something that PyQt widgets need to do - arbitrary signals can be emitted at any time - but Qt Designer needs to be know about the custom widget's signals so that it can connect them to slots in other widgets. The first change we make to the original widget is to declare the signals the widget is able to emit. Refer to the original example to see how the clock performs tasks such as painting and event handling. Instead of quoting the example in full, we will only note the changes that need to be made to the Analog Clock example in order to integrate it with Qt Designer. The PyAnalogClock widget is a version of the Analog Clock example supplied with Qt 4 and PyQt4 which provides a property to allow the clock to show the time in different time zones, a slot to enable the time zone to be changed in response to signals from other components, and two signals of its own to report changes to the time and time zone. Since the custom widget code does not need to be built or combined with the plugin code, very little extra work is required in order to make custom widgets work with Qt Designer. In Python, an additional plugin class is also needed, but developers only need to put the modules containing the custom widget and plugin class on special paths so that Qt Designer can find them. The custom widget code is often compiled separately into applications that use forms which reference the custom widget. The custom widget and the plugin class are then compiled together to create a plugin that Qt Designer can load. ![]() In C++, developers have to create an additional plugin class, based on QDesignerCustomWidgetInterface, that informs Qt Designer about the custom widget's name and which is used to create instances of it for use in forms created by the user. You can create custom widget plugins that Qt Designer loads at run time to allow custom widgets to be used directly in the user interface design process.Since a custom widget's class is a subclass of a standard widget's class, that standard widget can be used as a placeholder. Standard widgets can be promoted to act as placeholders for custom widgets. Fortunately, Qt Designer was written with this problem in mind, and there are two ways that custom widgets can be represented. However, many applications are designed to use custom widgets and components, and these often need to be made available to designers. Most of the standard Qt widgets are available to users of Qt Designer, and these can be used to create arbitrarily complex user interfaces. In many respects, it separates the design of an application from its function, leaving designers in control of its look and feel and basic usability while developers write the underlying application logic. Qt Designer is a user interface design tool for Qt applications that makes it possible for non-programmers to create user interfaces for applications. All the signals, slots and properties defined in Python are accessible in Designer's user interface and behave just the same as for widgets written in C++. In addition to the full range of standard Qt widgets, you can now install your own pure Python custom widgets and use them in your designs. Recent versions of PyQt contain something special for developers who use Qt Designer to design the user interfaces for their applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |