Python 3.10 pyqt5 Label won't change 'setPixmap' when needed

149 Views Asked by At

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.

0

There are 0 best solutions below