QObject

继承者: Phonon.ObjectDescriptionModel , Phonon.EffectDescriptionModel , Phonon.AudioOutputDeviceModel , QDrag , QNetworkCookieJar , QClipboard , QNetworkAccessManager , QHttp , QHelpSearchEngine , QFtp , QButtonGroup , QHelpEngineCore , QHelpEngine , QAbstractNetworkCache , QNetworkDiskCache , QActionGroup , QNetworkSession , QAction , QWidgetAction , QWebPluginFactory , QSyntaxHighlighter , QTimeLine , QNetworkConfigurationManager , QWebHistoryInterface , QUiLoader , QTextObject , QTextFrame , QTextTable , QTextBlockGroup , QTextList , QAbstractTextDocumentLayout , QPlainTextDocumentLayout , QWebPage , QAbstractAnimation , QVariantAnimation , QPropertyAnimation , QPauseAnimation , QAnimationGroup , QSequentialAnimationGroup , QParallelAnimationGroup , QInputContext , QSettings , QFileSystemWatcher , QGraphicsEffect , QGraphicsOpacityEffect , QGraphicsDropShadowEffect , QGraphicsBlurEffect , QGraphicsColorizeEffect , QAbstractUriResolver , QSvgRenderer , QGraphicsTransform , QGraphicsRotation , QGraphicsScale , QSqlDriver , QPluginLoader , QTranslator , QTimer , QGraphicsScene , QSocketNotifier , QDeclarativePropertyMap , QSignalMapper , QMimeData , QGraphicsItemAnimation , QDataWidgetMapper , QGraphicsAnchor , QDeclarativeExpression , QDeclarativeEngine , QDeclarativeContext , QItemSelectionModel , Phonon.BackendCapabilities.Notifier , QAbstractItemModel , QAbstractTableModel , QSqlQueryModel , QSqlTableModel , QSqlRelationalTableModel , QHelpContentModel , QDirModel , QAbstractProxyModel , QSortFilterProxyModel , QStandardItemModel , QProxyModel , QFileSystemModel , QAbstractListModel , QStringListModel , QHelpIndexModel , QDeclarativeComponent , QAbstractItemDelegate , QItemDelegate , QSqlRelationalDelegate , QStyledItemDelegate , QAbstractEventDispatcher , QEventLoop , QCoreApplication , QApplication , QAudioOutput , QThreadPool , QAudioInput , QSound , QShortcut , QSessionManager , QAbstractAudioInput , QUndoStack , QAbstractAudioOutput , QUndoGroup , QAbstractAudioDeviceInfo , QSystemTrayIcon , QCompleter , QGesture , QTapAndHoldGesture , QTapGesture , QSwipeGesture , QPinchGesture , QPanGesture , QAbstractVideoSurface , QScriptEngineDebugger , Phonon.MediaController , QThread , QScriptEngine , QValidator , QRegExpValidator , QDoubleValidator , QIntValidator , Phonon.AbstractMediaStream , QIODevice , QNetworkReply , QBuffer , QAbstractSocket , QUdpSocket , QLocalSocket , QFile , QTemporaryFile , QProcess , QTcpSocket , QTcpServer , QLocalServer , QAbstractTransition , QSignalTransition , QEventTransition , QMouseEventTransition , QKeyEventTransition , QGLShaderProgram , QAbstractState , QState , QStateMachine , QHistoryState , QFinalState , QGLShader , QStyle , QCommonStyle , QWindowsStyle , QPlastiqueStyle , QMacStyle , QCleanlooksStyle , QGtkStyle , QMotifStyle , QCDEStyle , QTextDocument , QAbstractMessageHandler , QMovie , QWebFrame , QSslSocket

概要

函数

虚函数

信号

静态函数

详细描述

PySide.QtCore.QObject 类是所有 Qt 对象的基类。

PySide.QtCore.QObject is the heart of the Qt 对象模型 . The central feature in this model is a very powerful mechanism for seamless object communication called 信号和槽 . You can connect a signal to a slot with PySide.QtCore.QObject.connect() and destroy the connection with PySide.QtCore.QObject.disconnect() . To avoid never ending notification loops you can temporarily block signals with PySide.QtCore.QObject.blockSignals() . The protected functions PySide.QtCore.QObject.connectNotify() and PySide.QtCore.QObject.disconnectNotify() make it possible to track connections.

QObjects organize themselves in 对象树 . When you create a PySide.QtCore.QObject with another object as parent, the object will automatically add itself to the parent's PySide.QtCore.QObject.children() list. The parent takes ownership of the object; i.e., it will automatically delete its children in its destructor. You can look for an object by name and optionally type using PySide.QtCore.QObject.findChild() or PySide.QtCore.QObject.findChildren() .

Every object has an PySide.QtCore.QObject.objectName() and its class name can be found via the corresponding PySide.QtCore.QObject.metaObject() (见 QMetaObject.className() ). You can determine whether the object's class inherits another class in the PySide.QtCore.QObject inheritance hierarchy by using the PySide.QtCore.QObject.inherits() 函数。

When an object is deleted, it emits a PySide.QtCore.QObject.destroyed() signal. You can catch this signal to avoid dangling references to QObjects .

QObjects can receive events through PySide.QtCore.QObject.event() and filter the events of other objects. See PySide.QtCore.QObject.installEventFilter() and PySide.QtCore.QObject.eventFilter() for details. A convenience handler, PySide.QtCore.QObject.childEvent() , can be reimplemented to catch child events.

Events are delivered in the thread in which the object was created; see Qt 中的线程支持 and PySide.QtCore.QObject.thread() for details. Note that event processing is not done at all for QObjects with no thread affinity ( PySide.QtCore.QObject.thread() returns zero). Use the PySide.QtCore.QObject.moveToThread() function to change the thread affinity for an object and its children (the object cannot be moved if it has a parent).

Last but not least, PySide.QtCore.QObject provides the basic timer support in Qt; see PySide.QtCore.QTimer for high-level support for timers.

Notice that the Q_OBJECT() macro is mandatory for any object that implements signals, slots or properties. You also need to run the Meta Object Compiler on the source file. We strongly recommend the use of this macro in all subclasses of PySide.QtCore.QObject regardless of whether or not they actually use signals, slots and properties, since failure to do so may lead certain functions to exhibit strange behavior.

All Qt widgets inherit PySide.QtCore.QObject . The convenience function PySide.QtCore.QObject.isWidgetType() returns whether an object is actually a widget. It is much faster than qobject_cast() < PySide.QtGui.QWidget *>( obj ) or obj -> PySide.QtCore.QObject.inherits() (” PySide.QtGui.QWidget ”).

Some PySide.QtCore.QObject functions, e.g. PySide.QtCore.QObject.children() , return a QObjectList . QObjectList is a typedef for QList < PySide.QtCore.QObject *>.

No copy constructor or assignment operator

PySide.QtCore.QObject has neither a copy constructor nor an assignment operator. This is by design. Actually, they are declared, but in a private section with the macro Q_DISABLE_COPY() . In fact, all Qt classes derived from PySide.QtCore.QObject (direct or indirect) use this macro to declare their copy constructor and assignment operator to be private. The reasoning is found in the discussion on Identity vs Value on the Qt 对象模型 页面。

The main consequence is that you should use pointers to PySide.QtCore.QObject (or to your PySide.QtCore.QObject subclass) where you might otherwise be tempted to use your PySide.QtCore.QObject subclass as a value. For example, without a copy constructor, you can't use a subclass of PySide.QtCore.QObject as the value to be stored in one of the container classes. You must store pointers.

自动连接

Qt's meta-object system provides a mechanism to automatically connect signals and slots between PySide.QtCore.QObject subclasses and their children. As long as objects are defined with suitable object names, and slots follow a simple naming convention, this connection can be performed at run-time by the QMetaObject.connectSlotsByName() 函数。

uic generates code that invokes this function to enable auto-connection to be performed between widgets on forms created with Qt Designer . More information about using auto-connection with Qt Designer is given in the Using a Designer UI File in Your Application 章节的 Qt Designer 手册。

动态特性

From Qt 4.2, dynamic properties can be added to and removed from PySide.QtCore.QObject instances at run-time. Dynamic properties do not need to be declared at compile-time, yet they provide the same advantages as static properties and are manipulated using the same API - using PySide.QtCore.QObject.property() to read them and PySide.QtCore.QObject.setProperty() to write them.

From Qt 4.3, dynamic properties are supported by Qt Designer , and both standard Qt widgets and user-created forms can be given dynamic properties.

国际化 (i18n)

所有 PySide.QtCore.QObject subclasses support Qt's translation features, making it possible to translate an application's user interface into different languages.

To make user-visible text translatable, it must be wrapped in calls to the PySide.QtCore.QObject.tr() function. This is explained in detail in the 编写翻译源代码 文档。

另请参阅

PySide.QtCore.QMetaObject QPointer QObjectCleanupHandler Q_DISABLE_COPY() Object Trees & Ownership

class PySide.QtCore. QObject ( [ parent=None ] )
参数: parent PySide.QtCore.QObject

构造对象采用父级对象 parent .

对象的父级可以被视为对象的所有者。例如, dialog box 父级于 OK and Cancel 按钮 (它包含的)。

父级对象的析构函数会销毁所有子级对象。

设置 parent to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window.

PySide.QtCore.QObject. blockSignals ( b )
参数: b PySide.QtCore.bool
返回类型: PySide.QtCore.bool

block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur.

返回值是先前值的 PySide.QtCore.QObject.signalsBlocked() .

注意: PySide.QtCore.QObject.destroyed() signal will be emitted even if the signals for this object have been blocked.

PySide.QtCore.QObject. childEvent ( arg__1 )
参数: arg__1 PySide.QtCore.QChildEvent

This event handler can be reimplemented in a subclass to receive child events. The event is passed in the event 参数。

QEvent.ChildAdded and QEvent.ChildRemoved events are sent to objects when children are added or removed. In both cases you can only rely on the child being a PySide.QtCore.QObject , or if PySide.QtCore.QObject.isWidgetType() returns true, a PySide.QtGui.QWidget . (This is because, in the ChildAdded case, the child is not yet fully constructed, and in the ChildRemoved case it might have been destructed already).

QEvent.ChildPolished events are sent to widgets when children are polished, or when polished children are added. If you receive a child polished event, the child's construction is usually completed. However, this is not guaranteed, and multiple polish events may be delivered during the execution of a widget's constructor.

For every child widget, you receive one ChildAdded event, zero or more ChildPolished events, and one ChildRemoved 事件。

ChildPolished event is omitted if a child is removed immediately after it is added. If a child is polished several times during construction and destruction, you may receive several child polished events for the same child, each time with a different virtual table.

PySide.QtCore.QObject. children ( )
返回类型:

返回子级对象的列表。 QObjectList 类被定义于 <QObject> 头文件,如下所示:

第一添加子级是 QList.first() 对象在列表中,且最后添加子级是 QList.last() 对象在列表中,即:新子级被追加在末尾。

注意:列表次序改变,当 PySide.QtGui.QWidget 子级 raised or lowered 。被提升 Widget 变为最后列表对象,被降低 Widget 变为第一列表对象。

PySide.QtCore.QObject. connect ( arg__1 , arg__2 , arg__3 [ , type=Qt.AutoConnection ] )
参数:
返回类型:

PySide.QtCore.bool

PySide.QtCore.QObject. connect ( arg__1 , arg__2 [ , type=Qt.AutoConnection ] )
参数:
返回类型:

PySide.QtCore.bool

PySide.QtCore.QObject. connect ( sender , signal , member [ , type=Qt.AutoConnection ] )
参数:
返回类型:

PySide.QtCore.bool

static PySide.QtCore.QObject. connect ( sender , signal , receiver , member [ , type=Qt.AutoConnection ] )
参数:
返回类型:

PySide.QtCore.bool

static PySide.QtCore.QObject. connect ( sender , signal , receiver , 方法 [ , type=Qt.AutoConnection ] )
参数:
返回类型:

PySide.QtCore.bool

static PySide.QtCore.QObject. connect ( arg__1 , arg__2 , arg__3 [ , type=Qt.AutoConnection ] )
参数:
返回类型:

PySide.QtCore.bool

PySide.QtCore.QObject. connectNotify ( signal )
参数: signal – str

This virtual function is called when something has been connected to signal in this object.

If you want to compare signal with a specific signal, use QLatin1String SIGNAL() macro as follows:

if QLatin1String(signal) == SIGNAL('valueChanged()'):
    # signal is valueChanged()
											

If the signal contains multiple parameters or parameters that contain spaces, call QMetaObject.normalizedSignature() on the result of the SIGNAL() 宏。

警告

This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.

PySide.QtCore.QObject. customEvent ( arg__1 )
参数: arg__1 PySide.QtCore.QEvent

This event handler can be reimplemented in a subclass to receive custom events. Custom events are user-defined events with a type value at least as large as the QEvent.User item of the QEvent.Type enum, and is typically a PySide.QtCore.QEvent subclass. The event is passed in the event 参数。

PySide.QtCore.QObject. deleteLater ( )

安排删除此对象。

The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. PySide.QtCore.QObject.deleteLater() is called on an object before QCoreApplication.exec() ), the object will be deleted once the event loop is started. If PySide.QtCore.QObject.deleteLater() is called after the main event loop has stopped, the object will not be deleted. Since Qt 4.8, if PySide.QtCore.QObject.deleteLater() is called on an object that lives in a thread with no running event loop, the object will be destroyed when the thread finishes.

注意:进入和离开新事件循环 (如,通过打开模态对话框) 会 not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which PySide.QtCore.QObject.deleteLater() was called.

注意

多次调用此函数是安全的;当交付首个延迟删除事件时,对象的任何待决事件均将从事件队列中被移除。

PySide.QtCore.QObject. destroyed ( [ object=None ] )
参数: object PySide.QtCore.QObject
PySide.QtCore.QObject. disconnect ( arg__1 , arg__2 )
参数:
  • arg__1 – str
  • arg__2 PyCallable
返回类型:

PySide.QtCore.bool

PySide.QtCore.QObject. disconnect ( signal , receiver , member )
参数:
返回类型:

PySide.QtCore.bool

此函数重载 PySide.QtCore.QObject.disconnect() .

Disconnects signal from 方法 of receiver .

A signal-slot connection is removed when either of the objects involved are destroyed.

static PySide.QtCore.QObject. disconnect ( sender , signal , receiver , member )
参数:
返回类型:

PySide.QtCore.bool

Disconnects signal in object sender from 方法 in object receiver . Returns true if the connection is successfully broken; otherwise returns false.

A signal-slot connection is removed when either of the objects involved are destroyed.

PySide.QtCore.QObject.disconnect() is typically used in three ways, as the following examples demonstrate.

0 may be used as a wildcard, meaning “any signal”, “any receiving object”, or “any slot in the receiving object”, respectively.

sender may never be 0. (You cannot disconnect signals from more than one object in a single call.)

signal is 0, it disconnects receiver and 方法 from any signal. If not, only the specified signal is disconnected.

receiver is 0, it disconnects anything connected to signal . If not, slots in objects other than receiver are not disconnected.

方法 is 0, it disconnects anything that is connected to receiver . If not, only slots named 方法 will be disconnected, and all other slots are left alone. The 方法 must be 0 if receiver is left out, so you cannot disconnect a specifically-named slot on all objects.

PySide.QtCore.QObject. disconnect ( receiver [ , member=0 ] )
参数:
返回类型:

PySide.QtCore.bool

此函数重载 PySide.QtCore.QObject.disconnect() .

Disconnects all signals in this object from receiver ‘s 方法 .

A signal-slot connection is removed when either of the objects involved are destroyed.

static PySide.QtCore.QObject. disconnect ( arg__1 , arg__2 , arg__3 )
参数:
返回类型:

PySide.QtCore.bool

static PySide.QtCore.QObject. disconnect ( sender , signal , receiver , member )
参数:
返回类型:

PySide.QtCore.bool

Disconnects signal in object sender from 方法 in object receiver . Returns true if the connection is successfully broken; otherwise returns false.

This function provides the same possibilities like disconnect(const PySide.QtCore.QObject *sender, const char *signal, const PySide.QtCore.QObject *receiver, const char *method) but uses PySide.QtCore.QMetaMethod to represent the signal and the method to be disconnected.

Additionally this function returnsfalse and no signals and slots disconnected if:

QMetaMethod() may be used as wildcard in the meaning “any signal” or “any slot in receiving object”. In the same way 0 can be used for receiver in the meaning “any receiving object”. In this case method should also be QMetaMethod(). sender parameter should be never 0.

PySide.QtCore.QObject. disconnectNotify ( signal )
参数: signal – str

This virtual function is called when something has been disconnected from signal in this object.

PySide.QtCore.QObject.connectNotify() for an example of how to compare signal with a specific signal.

警告

This function violates the object-oriented principle of modularity. However, it might be useful for optimizing access to expensive resources.

PySide.QtCore.QObject. dumpObjectInfo ( )

Dumps information about signal connections, etc. for this object to the debug output.

This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).

PySide.QtCore.QObject. dumpObjectTree ( )

Dumps a tree of children to the debug output.

This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).

PySide.QtCore.QObject. dynamicPropertyNames ( )
返回类型:

Returns the names of all properties that were dynamically added to the object using PySide.QtCore.QObject.setProperty() .

PySide.QtCore.QObject. emit ( arg__1 , arg__2 )
参数:
  • arg__1 – str
  • arg__2
返回类型:

PySide.QtCore.bool

PySide.QtCore.QObject. event ( arg__1 )
参数: arg__1 PySide.QtCore.QEvent
返回类型: PySide.QtCore.bool

此虚函数接收对象事件并返回 true,若事件 e 被识别并被处理。

PySide.QtCore.QObject.event() function can be reimplemented to customize the behavior of an object.

另请参阅

PySide.QtCore.QObject.installEventFilter() PySide.QtCore.QObject.timerEvent() QApplication.sendEvent() QApplication.postEvent() QWidget.event()

PySide.QtCore.QObject. eventFilter ( arg__1 , arg__2 )
参数:
返回类型:

PySide.QtCore.bool

过滤事件,若此对象已被安装成事件过滤器为 watched 对象。

在此函数的重实现中,若希望过滤 event 即:停止进一步处理,返回 true;否则返回 false。

范例:

class MainWindow(QMainWindow):
    def __init__(self):
        self.textEdit = QTextEdit()
        setCentralWidget(self.textEdit)
        textEdit.installEventFilter(self)
    def eventFilter(self, obj, event):
        if obj == textEdit:
            if event.type() == QEvent.KeyPress:
                keyEvent = event
                print "Ate key press", keyEvent.key()
                return true
            else:
                return false
        else:
            # pass the event on to the parent class
            return QMainWindow.eventFilter(self, obj, event)
												

Notice in the example above that unhandled events are passed to the base class's PySide.QtCore.QObject.eventFilter() function, since the base class might have reimplemented PySide.QtCore.QObject.eventFilter() for its own internal purposes.

警告

若在此函数中删除接收者对象,确保返回 true。否则,Qt 将把事件转发给被删除对象,且程序可能崩溃。

PySide.QtCore.QObject. findChild ( arg__1 [ , arg__2="" ] )
参数:
  • arg__1 PyTypeObject
  • arg__2 – unicode
返回类型:

PyObject

PySide.QtCore.QObject. findChildren ( arg__1 , arg__2 )
参数:
返回类型:

PySequence

PySide.QtCore.QObject. findChildren ( arg__1 [ , arg__2="" ] )
参数:
  • arg__1 PyTypeObject
  • arg__2 – unicode
返回类型:

PySequence

PySide.QtCore.QObject. inherits ( classname )
参数: classname – str
返回类型: PySide.QtCore.bool

Returns true if this object is an instance of a class that inherits className PySide.QtCore.QObject 子类,继承 className ;否则返回 false。

类被认为继承本身。

范例:

timer = QTimer()                    # QTimer inherits QObject
timer.inherits("QTimer")            # returns true
timer.inherits("QObject")           # returns true
timer.inherits("QAbstractButton")   # returns false
# QLayout inherits QObject and QLayoutItem
layout = QLayout()
layout.inherits("QObject")          # returns true
layout.inherits("QLayoutItem")      # returns false
												

If you need to determine whether an object is an instance of a particular class for the purpose of casting it, consider using qobject_cast<Type *>(object) instead.

另请参阅

PySide.QtCore.QObject.metaObject() qobject_cast()

PySide.QtCore.QObject. installEventFilter ( arg__1 )
参数: arg__1 PySide.QtCore.QObject

安装事件过滤器 filterObj 在此对象。例如:

monitoredObj.installEventFilter(filterObj)
												

An event filter is an object that receives all events that are sent to this object. The filter can either stop the event or forward it to this object. The event filter filterObj 接收事件凭借其 PySide.QtCore.QObject.eventFilter() function. The PySide.QtCore.QObject.eventFilter() function must return true if the event should be filtered, (i.e. stopped); otherwise it must return false.

If multiple event filters are installed on a single object, the filter that was installed last is activated first.

Here's a KeyPressEater class that eats the key presses of its monitored objects:

class KeyPressEater(QObject):
    def eventFilter(self, obj, event):
        if event.type() == QEvent.KeyPress:
            print "Ate key press", event.key()
            return True
        else:
            # standard event processing
            return QObject.eventFilter(self, obj, event)
												

And here's how to install it on two widgets:

keyPressEater = KeyPressEater(self)
pushButton = QPushButton(self)
listView = QListView(self)
pushButton.installEventFilter(keyPressEater)
listView.installEventFilter(keyPressEater)
												

PySide.QtGui.QShortcut class, for example, uses this technique to intercept shortcut key presses.

警告

If you delete the receiver object in your PySide.QtCore.QObject.eventFilter() function, be sure to return true. If you return false, Qt sends the event to the deleted object and the program will crash.

Note that the filtering object must be in the same thread as this object. If filterObj is in a different thread, this function does nothing. If either filterObj or this object are moved to a different thread after calling this function, the event filter will not be called until both objects have the same thread affinity again (it is not removed).

PySide.QtCore.QObject. isWidgetType ( )
返回类型: PySide.QtCore.bool

Returns true if the object is a widget; otherwise returns false.

Calling this function is equivalent to calling inherits(” PySide.QtGui.QWidget ”), except that it is much faster.

PySide.QtCore.QObject. killTimer ( id )
参数: id PySide.QtCore.int

杀除计时器采用计时器标识符, id .

计时器标识符被返回通过 PySide.QtCore.QObject.startTimer() when a timer event is started.

PySide.QtCore.QObject. metaObject ( )
返回类型: PySide.QtCore.QMetaObject

返回指向此对象的元对象的指针。

A meta-object contains information about a class that inherits PySide.QtCore.QObject , e.g. class name, superclass name, properties, signals and slots. Every PySide.QtCore.QObject subclass that contains the Q_OBJECT() macro will have a meta-object.

The meta-object information is required by the signal/slot connection mechanism and the property system. The PySide.QtCore.QObject.inherits() function also makes use of the meta-object.

If you have no pointer to an actual object instance but still want to access the meta-object of a class, you can use staticMetaObject .

范例:

obj = QPushButton()
obj.metaObject().className()                # returns "QPushButton"
QPushButton.staticMetaObject.className()    # returns "QPushButton"
												

另请参阅

staticMetaObject

PySide.QtCore.QObject. moveToThread ( thread )
参数: thread PySide.QtCore.QThread

更改此对象及其子级的线程亲缘关系。对象无法被移动,若它有父级。事件处理将继续在 targetThread .

To move an object to the main thread, use QApplication.instance() to retrieve a pointer to the current application, and then use QApplication.thread() to retrieve the thread in which the application lives. For example:

myObject.moveToThread(QApplication.instance().thread())
												

targetThread is zero, all event processing for this object and its children stops.

Note that all active timers for the object will be reset. The timers are first stopped in the current thread and restarted (with the same interval) in the targetThread . As a result, constantly moving an object between threads can postpone timer events indefinitely.

A QEvent.ThreadChange event is sent to this object just before the thread affinity is changed. You can handle this event to perform any special processing. Note that any new events that are posted to this object will be handled in the targetThread .

警告

此函数是 not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only “push” an object from the current thread to another thread, it cannot “pull” an object from any arbitrary thread to the current thread.

PySide.QtCore.QObject. objectName ( )
返回类型: unicode

This property holds the name of this object.

可按名称 (和类型) 查找对象,使用 PySide.QtCore.QObject.findChild() . You can find a set of objects with PySide.QtCore.QObject.findChildren() .

print "MyClass::setPrecision(): (%s) invalid precision %f" % \
       (qPrintable(objectName()), newPrecision)
												

默认情况下,此特性包含空字符串。

PySide.QtCore.QObject. parent ( )
返回类型: PySide.QtCore.QObject

返回指向父级对象的指针。

PySide.QtCore.QObject. 特性 ( name )
参数: name – str
返回类型: object

返回值为对象的 name 特性。

返回的变体是无效的,若没有这样的特性存在。

所有可用特性的有关信息,提供透过 PySide.QtCore.QObject.metaObject() and PySide.QtCore.QObject.dynamicPropertyNames() .

PySide.QtCore.QObject. receivers ( signal )
参数: signal – str
返回类型: PySide.QtCore.int

Returns the number of receivers connected to the signal .

Since both slots and signals can be used as receivers for signals, and the same connections can be made many times, the number of receivers is the same as the number of connections made from this signal.

When calling this function, you can use the SIGNAL() macro to pass a specific signal:

if receivers(SIGNAL('valueChanged()')) > 0:
    data = get_the_value()  # expensive operation
    self.valueChanged(data)
												

As the code snippet above illustrates, you can use this function to avoid emitting a signal that nobody listens to.

警告

This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.

static PySide.QtCore.QObject. registerUserData ( )
返回类型: PySide.QtCore.uint
PySide.QtCore.QObject. removeEventFilter ( arg__1 )
参数: arg__1 PySide.QtCore.QObject

Removes an event filter object obj from this object. The request is ignored if such an event filter has not been installed.

All event filters for this object are automatically removed when this object is destroyed.

It is always safe to remove an event filter, even during event filter activation (i.e. from the PySide.QtCore.QObject.eventFilter() function).

PySide.QtCore.QObject. sender ( )
返回类型: PySide.QtCore.QObject

Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function from this object's thread context.

The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.

警告

This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.

警告

As mentioned above, the return value of this function is not valid when the slot is called via a Qt.DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.

PySide.QtCore.QObject. senderSignalIndex ( )
返回类型: PySide.QtCore.int

Returns the meta-method index of the signal that called the currently executing slot, which is a member of the class returned by PySide.QtCore.QObject.sender() . If called outside of a slot activated by a signal, -1 is returned.

For signals with default parameters, this function will always return the index with all parameters, regardless of which was used with PySide.QtCore.QObject.connect() . For example, the signal destroyed(QObject *obj = 0) will have two different indexes (with and without the parameter), but this function will always return the index with a parameter. This does not apply when overloading signals with different parameters.

警告

This function violates the object-oriented principle of modularity. However, getting access to the signal index might be useful when many signals are connected to a single slot.

警告

The return value of this function is not valid when the slot is called via a Qt.DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.

PySide.QtCore.QObject. setObjectName ( name )
参数: name – unicode

This property holds the name of this object.

可按名称 (和类型) 查找对象,使用 PySide.QtCore.QObject.findChild() . You can find a set of objects with PySide.QtCore.QObject.findChildren() .

print "MyClass::setPrecision(): (%s) invalid precision %f" % \
       (qPrintable(objectName()), newPrecision)
												

默认情况下,此特性包含空字符串。

PySide.QtCore.QObject. setParent ( arg__1 )
参数: arg__1 PySide.QtCore.QObject

使对象子级 parent .

另请参阅

PySide.QtCore.QObject.parent() QWidget.setParent()

PySide.QtCore.QObject. setProperty ( name , value )
参数:
  • name – str
  • value – object
返回类型:

PySide.QtCore.bool

Sets the value of the object's name 特性到 value .

If the property is defined in the class using Q_PROPERTY then true is returned on success and false otherwise. If the property is not defined using Q_PROPERTY, and therefore not listed in the meta-object, it is added as a dynamic property and false is returned.

所有可用特性的有关信息,提供透过 PySide.QtCore.QObject.metaObject() and PySide.QtCore.QObject.dynamicPropertyNames() .

Dynamic properties can be queried again using PySide.QtCore.QObject.property() and can be removed by setting the property value to an invalid PySide.QtCore.QVariant . Changing the value of a dynamic property causes a PySide.QtCore.QDynamicPropertyChangeEvent to be sent to the object.

注意

Dynamic properties starting with “_q_” are reserved for internal purposes.

PySide.QtCore.QObject. signalsBlocked ( )
返回类型: PySide.QtCore.bool

Returns true if signals are blocked; otherwise returns false.

信号不被阻塞,默认情况下。

PySide.QtCore.QObject. startTimer ( interval )
参数: interval PySide.QtCore.int
返回类型: PySide.QtCore.int

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

A timer event will occur every interval milliseconds until PySide.QtCore.QObject.killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.

The virtual PySide.QtCore.QObject.timerEvent() function is called with the PySide.QtCore.QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.

If multiple timers are running, the QTimerEvent.timerId() can be used to find out which timer was activated.

范例:

class MyObject(QObject):
    def __init__(self, parent):
        QObject.__init__(self, parent)
        self.startTimer(50)         # 50-millisecond timer
        self.startTimer(1000)       # 1-second timer
        self.startTimer(60000)      # 1-minute timer
    def timerEvent(self, event):
        print "Timer ID:", event.timerId()
												

注意: PySide.QtCore.QTimer ‘s accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.

PySide.QtCore.QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a PySide.QtCore.QBasicTimer class that is more lightweight than PySide.QtCore.QTimer and less clumsy than using timer IDs directly.

PySide.QtCore.QObject. thread ( )
返回类型: PySide.QtCore.QThread

返回对象所在的线程。

PySide.QtCore.QObject. timerEvent ( arg__1 )
参数: arg__1 PySide.QtCore.QTimerEvent

This event handler can be reimplemented in a subclass to receive timer events for the object.

PySide.QtCore.QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event 参数。

PySide.QtCore.QObject. tr ( arg__1 [ , arg__2=0 [ , arg__3=-1 ] ] )
参数:
  • arg__1 – str
  • arg__2 – str
  • arg__3 PySide.QtCore.int
返回类型:

unicode

返回翻译版本的 sourceText , optionally based on a disambiguation string and value of n for strings containing plurals; otherwise returns sourceText itself if no appropriate translated string is available.

范例:

def createMenus(self):
    fileMenu = menuBar().addMenu("&File")
    ...
												

If the same sourceText is used in different roles within the same context, an additional identifying string may be passed in disambiguation (0 by default). In Qt 4.4 and earlier, this was the preferred way to pass comments to translators.

范例:

def __init__(self):
    senderLabel = QLabel(self.tr("Name:"))
    recipientLabel = QLabel(self.tr("Name:", "recipient"))
    # ...
    ...
												

编写翻译源代码 for a detailed description of Qt's translation mechanisms in general, and the 消歧 section for information on disambiguation.

警告

This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.

另请参阅

PySide.QtCore.QObject.trUtf8() QApplication.translate() QTextCodec.setCodecForTr() Qt 国际化

PySide.QtCore.QObject. trUtf8 ( arg__1 [ , arg__2=0 [ , arg__3=-1 ] ] )
参数:
  • arg__1 PyUnicode
  • arg__2 – str
  • arg__3 PySide.QtCore.int
返回类型:

unicode

PySide.QtCore.QObject. trUtf8 ( arg__1 [ , arg__2=0 [ , arg__3=-1 ] ] )
参数:
  • arg__1 – str
  • arg__2 – str
  • arg__3 PySide.QtCore.int
返回类型:

unicode

返回翻译版本的 sourceText , or QString::fromUtf8( sourceText ) if there is no appropriate version. It is otherwise identical to tr( sourceText , disambiguation , n ).

Note that using the Utf8 variants of the translation functions is not required if CODECFORTR is already set to UTF-8 in the qmake project file and QTextCodec::setCodecForTr(“UTF-8”) is used.

警告

This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.

警告

For portability reasons, we recommend that you use escape sequences for specifying non-ASCII characters in string literals to PySide.QtCore.QObject.trUtf8() 。例如:

label.setText(self.tr("F\374r \310lise"))
												

另请参阅

PySide.QtCore.QObject.tr() QApplication.translate() Qt 国际化