self.language = QAction("English", self)什么意思
时间: 2024-06-07 12:07:01 浏览: 3
这是在 PyQt5 中创建一个 QAction(动作) 对象,并将其命名为 "English"。"self" 是指当前窗口或应用程序,这里是在当前窗口中创建该对象。这个动作对象可以被添加到菜单栏、工具栏等界面元素中,用于触发一些操作或事件。在这个例子中,当用户选择 "English" 时,可能会触发一些语言切换的操作或事件。
相关问题
for cam in cams: exec("action_%s = QAction('%s')" % (cam, cam)) exec("popMenu.addAction(action_%s)" % cam) x = self.groupBox_5.mapToGlobal(self.cameraButton.pos()).x() y = self.groupBox_5.mapToGlobal(self.cameraButton.pos()).y() y = y + self.cameraButton.frameGeometry().height() pos = QPoint(x, y) action = popMenu.exec_(pos) if action: self.det_thread.source = action.text() self.det_thread.is_continue = True cap = cv2.VideoCapture(int(action.text())) for i in range(10): r,img = cap.read() self.raw_img = img
这段代码实现了一个弹出式菜单,用于选择摄像头,并且可以从所选择的摄像头中读取图像。具体来说:
1. 首先,通过循环遍历 `cams` 列表中的每个元素 `cam`,使用 `exec()` 函数生成一个名为 `action_cam` 的 QAction 对象,并将其添加到 `popMenu` 菜单中。
2. 然后,使用 PyQt5 中的 `mapToGlobal()` 函数计算出 `cameraButton` 按钮在屏幕上的绝对位置,并将其作为弹出菜单的位置。
3. 当用户选择菜单中的一个摄像头时,将其文本信息存储在 `self.det_thread.source` 变量中,并将 `self.det_thread.is_continue` 标志设置为 True。
4. 最后,使用 OpenCV 的 `VideoCapture()` 函数打开所选择的摄像头,并使用 `cap.read()` 函数从摄像头中读取 10 帧图像,并将读取的图像存储在 `self.raw_img` 变量中。
Got keys from plugin meta data ("ibus") QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforminputcontexts" ... loaded library "/home/rvbust/.local/lib/python3.10/site-packages/PyQt5/Qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so" QFactoryLoader::QFactoryLoader() checking directory path "/home/rvbust/.local/lib/python3.10/site-packages/PyQt5/Qt5/plugins/styles" ... QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/styles" ... Traceback (most recent call last): File "/home/rvbust/Documents/FlexLocation_new/ViewerApp.py", line 30, in <module> main() File "/home/rvbust/Documents/FlexLocation_new/ViewerApp.py", line 24, in main main_window = GlyphViewerApp() File "/home/rvbust/Documents/FlexLocation_new/ViewerApp.py", line 10, in __init__ self.setup() File "/home/rvbust/Documents/FlexLocation_new/ViewerApp.py", line 15, in setup self.ui.setupUi(self) File "/home/rvbust/Documents/FlexLocation_new/glyph_view.py", line 33, in setupUi self.actionLoadCloud = QAction(MainWindow) TypeError: 'PySide6.QtGui.QAction.__init__' called with wrong argument types: PySide6.QtGui.QAction.__init__(GlyphViewerApp) Supported signatures: PySide6.QtGui.QAction.__init__(Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], str, Optional[PySide6.QtCore.QObject] = None) PySide6.QtGui.QAction.__init__(Optional[PySide6.QtCore.QObject] = None) PySide6.QtGui.QAction.__init__(str, Optional[PySide6.QtCore.QObject] = None) QLibraryPrivate::unload succeeded on "/home/rvbust/.local/lib/python3.10/site-packages/PyQt5/Qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so" QLibraryPrivate::unload succeeded on "/home/rvbust/.local/lib/python3.10/site-packages/PyQt5/Qt5/plugins/platformthemes/libqgtk3.so" QLibraryPrivate::unload succeeded on "/home/rvbust/.local/lib/python3.10/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so" QLibraryPrivate::unload succeeded on "Xcursor" (faked)
这个错误信息出现在实例化 `GlyphViewerApp` 对象时,调用了 `setup` 方法。具体来说,`GlyphViewerApp` 继承自 `QtWidgets.QMainWindow`,而 `setup` 方法中又调用了 `glyph_view.ui` 模块中的 `setupUi` 方法创建了一些 UI 控件,其中包括一个 `QAction` 对象。但是在创建 `QAction` 对象时,传入的参数类型不正确,导致了这个错误。
解决这个问题的方法是,在 `glyph_view.ui` 模块中找到创建 `QAction` 对象的代码,确保参数类型正确。根据错误信息中的提示,`QAction.__init__` 方法支持多种不同的参数类型,需要根据实际情况选择正确的参数类型传入。例如,可以尝试修改为:
```python
self.actionLoadCloud = QAction("Load Cloud", self)
```
这里将第一个参数修改为字符串类型,表示 `QAction` 对象的文本标签。同时,将第二个参数指定为 `self`,表示 `QAction` 对象的父对象为 `GlyphViewerApp` 对象。这样就可以避免参数类型不匹配的错误了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)