gpt4 book ai didi

python - 在 pythonQt 中使用 BoolResult

转载 作者:行者123 更新时间:2023-11-28 04:47:34 25 4
gpt4 key购买 nike

在 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” bool 值?

它尝试了以下不起作用:

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,例如如果我们看到 docs Qt 的:

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)

关于python - 在 pythonQt 中使用 BoolResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48965903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com