BoolResult被转换为指针:
bool ok;
int i = QInputDialog::getInt(this, tr("QInputDialog::getInteger()"),
tr("Percentage:"), 25, 0, 100, 1, &ok);
if (ok)
integerLabel->setText(tr("%1%").arg(i));
如何检索" ok" bool in pyQt / pythonQt?
尝试了下面的工作:
from PythonQt.QtGui import QInputDialog, QWidget
from PythonQt.QtCore import Qt, QTimer
from PythonQt import BoolResult
...
x = QWidget()
x.setAttribute(Qt.WA_DeleteOnClose)
ok = BoolResult()
i = QInputDialog.getInt(x, "test", "hallo", 1000, None, None, None, ok)
print("ok:", ok)
print("i:", i)
print("i:", i)
导致
2/24/2018 17:49:42 pyTSon.PluginHost.onMenuItemEvent Error Error calling onMenuItemEvent of python plugin Auto Channel Commander: Traceback (most recent call last):
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\pluginhost.py", line 663, in onMenuItemEvent
plugin.onMenuItemEvent(schid, atype, locid, selectedItemID)
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\autoCommander\__init__.py", line 64, in onMenuItemEvent
i = QInputDialog.getInt(x, "test", "hallo", 1000, None, None, None, ok)
ValueError: Could not find matching overload for given arguments:
(QWidget(0x2759aa87560) , 'test', 'hallo', 1000, None, None, None, BoolResult(False))
The following slots are available:
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue, int step, PythonQt.BoolResult ok, Qt::WindowFlags flags) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue, int step, PythonQt.BoolResult ok) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue, int step) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue) -> int
static getInt(QWidget parent, QString title, QString label, int value) -> int
static getInt(QWidget parent, QString title, QString label) -> int
答案 0 :(得分:1)
您的案例中的问题是您必须指定适当的值,而不应使用None
,例如,如果我们看到Qt的docs:
int QInputDialog :: getInt(QWidget * parent,const QString& title,const QString& label,int value = 0,int min = -2147483647,int max = 2147483647,int step = 1,bool * ok = Q_NULLPTR,Qt :: WindowFlags flags = Qt :: WindowFlags())
所以可能的解决方案是复制这些值:
ok = BoolResult()
i = QInputDialog.getInt(push1, "test", "hallo", 1000, -2147483647, 2147483647, 1, ok)
print("ok:", ok)
print("i:", i)