Python 3.10 Pyqt5标签赢得了更改' setPixmap'需要时

发布于 2025-01-23 19:00:22 字数 1978 浏览 3 评论 0原文

我目前正在运行python 3.10,并且在比赛/案例中并有一个奇怪的结果。让我解释一下:

我的代码图像

class Test(QtWidgets.QMainWindow):
def __init__(self):
    super(Test, self).__init__()

    # comboBox changes = image gets displayed on app 'WORKING'
    self.comboBoxIS.currentTextChanged.connect(partial(self.loadIsCombo, Testing=False))

    # Clicking 'Test' button to see if image is on the screen. At this point is on the app so technically it is.
    self.pushButtonIS_2.clicked.connect(partial(self.loadIsCombo, Testing=True))

def bufferIsCombo(self, Testing=False):
selectedItem = self.comboBoxIS.currentText()
bufferImg = 'resources/ui/buffering.png'
match selectedItem:
            case "Test 1":
                img = config['Test1']['Test1a']
                imgConf = config['Test1'].getfloat('Test1b')
                self.labelIS2.setText(str(imgConf))
                self.labelISConfig.setPixmap(QtGui.QPixmap(img))
                self.pushButtonIS_2.setEnabled(True) # Enable test button
                if Testing:
                    # Since the app contains the image i want to change it to another 'buffering'
                    self.labelISConfig.setPixmap(QtGui.QPixmap(bufferImg))
                    # This setPixmap wont get applied until handler returns but by that time is to late.
                    # imageSearchTest() come back as false positibe because it was on the application
                    functions.imageSearchTest()
            case "Test 2":
                pass
            case "Test 20":
                pass
          

一切正常运行,直到我遇到IF TESTING:strate for the if testing:statem 。新的self.labelisconfig.setpixmap(qtgui.qpixmap(bufferimg))在函数image> images eraperechtest之后才会更改。

问题是我在应用程序上显示该图像并运行图像搜索功能,因此它给了我误报,因为它在应用程序上找到了图像。为了解决此问题,我想将标签PixMap更改为DIF映像Bufferimg在功能开始运行之前,我不会得到那个假阳性。

I'm currently running python 3.10 and within a match/case and having a weird outcome. Let me explain:

Image of my code

class Test(QtWidgets.QMainWindow):
def __init__(self):
    super(Test, self).__init__()

    # comboBox changes = image gets displayed on app 'WORKING'
    self.comboBoxIS.currentTextChanged.connect(partial(self.loadIsCombo, Testing=False))

    # Clicking 'Test' button to see if image is on the screen. At this point is on the app so technically it is.
    self.pushButtonIS_2.clicked.connect(partial(self.loadIsCombo, Testing=True))

def bufferIsCombo(self, Testing=False):
selectedItem = self.comboBoxIS.currentText()
bufferImg = 'resources/ui/buffering.png'
match selectedItem:
            case "Test 1":
                img = config['Test1']['Test1a']
                imgConf = config['Test1'].getfloat('Test1b')
                self.labelIS2.setText(str(imgConf))
                self.labelISConfig.setPixmap(QtGui.QPixmap(img))
                self.pushButtonIS_2.setEnabled(True) # Enable test button
                if Testing:
                    # Since the app contains the image i want to change it to another 'buffering'
                    self.labelISConfig.setPixmap(QtGui.QPixmap(bufferImg))
                    # This setPixmap wont get applied until handler returns but by that time is to late.
                    # imageSearchTest() come back as false positibe because it was on the application
                    functions.imageSearchTest()
            case "Test 2":
                pass
            case "Test 20":
                pass
          

Everything works well until I run into the if Testing: statement. The new self.labelISConfig.setPixmap(QtGui.QPixmap(bufferImg)) will not change until after the function imagesearchTest.

The issue with that is I'm displaying that image on my application and running an image search function so it gives me a false positive because it finds the image on the application. To fix this I would like to change the label pixmap to a dif image bufferImg before the function starts running so I don't get that false positive.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文