在python中使用PyQt5按下按钮时更改QML中的标签[复制](Change label in QML when button is pressed using PyQt5 in python [duplicate])
这个问题在这里已经有了答案:
我试图用PyQt5和QML做一个简单的任务:有一个按钮在被点击时改变标签。 我已经能够在按下按钮时执行python函数,但我不知道如何更改标签中的文本。
这是一个简单的例子:
main.py
from PyQt5.QtWidgets import * from PyQt5.QtQml import * from PyQt5.QtCore import * import sys def onClicked(): print('handler called') if __name__ == '__main__': app = QApplication(sys.argv) engine = QQmlApplicationEngine() engine.load(QUrl('main.qml')) win = engine.rootObjects()[0] button = win.findChild(QObject, 'myButton') button.messageRequired.connect(onClicked) sys.exit(app.exec_())
main.qml
import QtQuick 2.7 import QtQuick.Controls 2.3 import QtQuick.Window 2.3 ApplicationWindow{ title: qsTr('Quomodo') id: mainWindow width: 480 height: 640 visible: true Column { anchors.horizontalCenter: parent.horizontalCenter spacing: 8 padding: 8 Button { signal messageRequired objectName: "myButton" text: qsTr("Work") highlighted: true onClicked: messageRequired() } Label { text: qsTr("Time") anchors.horizontalCenter: parent.horizontalCenter } } }
例如,如何将标签的文本更改为“下一个”?
注意:这不是QML的重复,它没有取得从PyQt插槽收到的对象的所有权 。 这个问题是关于Python和QML之间数据的所有权,并没有回答这个问题。
This question already has an answer here:
I'm trying to do a simple task with PyQt5 and QML: have a button that changes a label when it is clicked. I've been able to execute a python function when the button is pressed, but I don't know how to change the text in the label.
This is a minimal example:
main.py
from PyQt5.QtWidgets import * from PyQt5.QtQml import * from PyQt5.QtCore import * import sys def onClicked(): print('handler called') if __name__ == '__main__': app = QApplication(sys.argv) engine = QQmlApplicationEngine() engine.load(QUrl('main.qml')) win = engine.rootObjects()[0] button = win.findChild(QObject, 'myButton') button.messageRequired.connect(onClicked) sys.exit(app.exec_())
main.qml
import QtQuick 2.7 import QtQuick.Controls 2.3 import QtQuick.Window 2.3 ApplicationWindow{ title: qsTr('Quomodo') id: mainWindow width: 480 height: 640 visible: true Column { anchors.horizontalCenter: parent.horizontalCenter spacing: 8 padding: 8 Button { signal messageRequired objectName: "myButton" text: qsTr("Work") highlighted: true onClicked: messageRequired() } Label { text: qsTr("Time") anchors.horizontalCenter: parent.horizontalCenter } } }
How can I change the text of the label to "Next", for instance?
Note: This is not a duplicate of QML not taking ownership of object received from PyQt slot. That question is about ownership of the data between Python and QML, and doesn't answer this question.
原文:https://stackoverflow.com/questions/50115934
最满意答案
你使用
CAP_PROP_EXPOSURE
还是cv2.CAP_PROP_EXPOSURE
?在我的OpenCV 3.1.0中,Python 2.7有这样的价值:
print cv2.CAP_PROP_EXPOSURE 15
Do you use
CAP_PROP_EXPOSURE
orcv2.CAP_PROP_EXPOSURE
?In my OpenCV 3.1.0, Python 2.7 there is such value:
print cv2.CAP_PROP_EXPOSURE 15
相关问答
更多-
以下是C ++ / WinAPI中的示例,您可以如何在设置对话框中设置/取消设置VIDEO INPUT引脚。 此代码假定,该复选框是主对话框的子元素; 可能会出现这种情况,当它们嵌套在选项卡控件“自定义设置”中时,所以在这种情况下,您首先需要找到该选项卡。 #include
#include #include #include -
并不是所有的摄像机都支持所有的参数 - 实际上它们是OpenCV库最麻烦的部分之一。 每种相机类型 - 从Android相机到usb相机到专业的相机提供了一个不同的界面来设置它的参数。 而OpenCV代码中有许多分支支持其中许多,但当然并不是所有的可能性都被覆盖。 你可以做的是调查你的相机驱动程序,打补丁到OpenCV并发送到code.opencv.org。 这样一来,别人会喜欢你的工作,就像你喜欢别人一样。 您的相机也可能不支持您的要求 - 大多数USB摄像头便宜而简单。 也许该参数不可用于修改。 如果您 ...
-
你的C\Python有opencv_ffmpeg.dll或opencv_ffmpeg_64.dll ? 你需要有这些dlls才能播放视频。 查看此链接了解更多详情。 Do you have opencv_ffmpeg.dll or opencv_ffmpeg_64.dll in your C\Python. You need to have these dlls in order to play videos. Check this link for more details.
-
您需要使用流URL来初始化VideoCapture,而不是网页URL 当用m3u8进行初始化时,这是有效的。 如何做到这一点已经在这个问题上描述: 我怎样才能得到一个YouTube直播流的实际视频网址? 这是Devstr在评论中发布的同样的方法,只有另一篇文章。 You need to use the stream URL for Initializing the VideoCapture, not the webpage URL when initializing with the m3u8 this w ...
-
你使用CAP_PROP_EXPOSURE还是cv2.CAP_PROP_EXPOSURE ? 在我的OpenCV 3.1.0中,Python 2.7有这样的价值: print cv2.CAP_PROP_EXPOSURE 15 Do you use CAP_PROP_EXPOSURE or cv2.CAP_PROP_EXPOSURE? In my OpenCV 3.1.0, Python 2.7 there is such value: print cv2.CAP_PROP_EXPOSURE 15
-
函数waitKey()无限地等待一个键事件(当delay <= 0时)或者等待延迟毫秒,当它为正时。 如果FPS等于20,那么您应该在连续帧之间等待0.05秒。 所以在waitKey(50)之后放置waitKey(50) ,它将以正常速度显示。 The function waitKey() waits for a key event infinitely (when delay <= 0) or for delay milliseconds, when it is positive. If the FPS ...
-
通过“点击对焦”和曝光控制进行GPUImage视频捕捉(GPUImage video capture with 'tap-to-focus' and exposure control)[2021-09-16]
得到它,部分: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchPoint = [touch locationInView:self.view]; if([videoCamera.inputCamera isFocusPointOfInterestSupported]&&[videoCamera. ... -
你应该使用cv2.waitKey(delay_in_ms) ,而不是cv2.waitKey(delay_in_ms) time.sleep(...) 。 来自OpenCV doc : 此函数是HighGUI中唯一可以获取和处理事件的方法,因此需要定期调用它以进行正常事件处理,除非在负责事件处理的环境中使用HighGUI。 如果您不调用waitKey ,则不会刷新Windows内容(由imshow创建)。 You should use cv2.waitKey(delay_in_ms), instead of ...
-
有一种方法可用于在OpenCV中更改VideoCapture对象的属性,可用于设置输入图像的曝光。 cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_EXPOSURE, 40) 但是,并非所有摄像机都支持此参数。 每种摄像机类型都提供不同的界面来设置其参数。 OpenCV代码中有许多分支支持尽可能多的分支,但当然不是所有的可能性都包括在内。 我的相机也是如此。 所以我必须找到一个不同的解决方案。 那是从命令行终端使用v4l2_ctl实用程序。 v4l2-ctl ...
-
发现错误...... Python从零开始索引计数器... Found the error... Python starts index counters from zero...