在 pythonQt 中使用 BoolResult
Use BoolResult in pythonQt
在 C++ 中 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));
如何检索 pyQt/pythonQt 中的 "ok" 布尔值?
它尝试了以下无效:
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
你的问题是你必须分配适当的值,你不应该使用 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)
在 C++ 中 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));
如何检索 pyQt/pythonQt 中的 "ok" 布尔值?
它尝试了以下无效:
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
你的问题是你必须分配适当的值,你不应该使用 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)