2017-06-03 101 views
1

我正在嘗試使用QtGlobal Header File中的某些功能,但無法識別它們的位置。即,qMax和qMin功能。PyQt5中是否可以訪問QtGlobal聲明?

我通過以下方式使用它試圖:

qMax(190, fontHeight * 12) 
QtCore.qMax(190, fontHeight * 12) 
QtGui.qMax(190, fontHeight * 12) 
QtWidgets.qMax(190, fontHeight * 12) 

第一種方法有以下回應:

NameError: name 'qMax' is not defined 

最後3都具有基本相同的錯誤,只是QtCore用我嘗試導入它們的任何模塊替換。

AttributeError: module 'PyQt5.QtCore' has no attribute 'qMax' 

我看不出爲什麼這些函數不會被包含在某個地方,但我不知道如何使用它們。

那麼他們包括,如果是的話,我該怎麼稱呼他們?

回答

2

的QtGlobal功能是QtCore模塊,但不包括一切:

>>> print(' '.join(x for x in dir(QtCore) if x[0] == 'q')) 
qAbs qAddPostRoutine qAddPreRoutine qChecksum qCompress qCritical qDebug 
qErrnoWarning qFatal qFloatDistance qFormatLogMessage qFuzzyCompare qInf 
qInstallMessageHandler qIsFinite qIsInf qIsNaN qIsNull qQNaN 
qRegisterResourceData qRemovePostRoutine qRound qRound64 qSNaN 
qSetFieldWidth qSetMessagePattern qSetPadChar qSetRealNumberPrecision 
qSharedBuild qUncompress qUnregisterResourceData qVersion qWarning 
qrand qsrand 

在有包括qMinqMax似乎沒有什麼意義。 Python已經有minmax,它們提供了非常優越的API。

PS:

我想我要補充一點,min/max將正常使用Qt類型,只要它們實現的小於操作符(__lt__):

>>> x = QtGui.QStandardItem('1') 
>>> y = QtGui.QStandardItem('2') 
>>> min(x, y).text() 
'1' 
>>> max(x, y).text() 
'2' 
相關問題