0

I have a question regarding PyQGIS.

I am currently developing a plugin, and I wish to update a window's label as soon as the window opens, without having to click on a button.

Here is what I do: I open my plugin, and when clicking on a button, it opens a second window. On that window, I have a label with a default value (that value comes from the ui file, created with QtCreator). The goal is, as soon as the window opens, to check another class attribute. If that attribute has a value, the label must be updated with that value. If the class attribute is 'None', then the label keeps the default value. I must not click on a button, or hover the text. However, I did not find any sort of signal allowing to check a label when a window opens.

I tried calling a method directly in the attribute definition, but it does not work:

class MySecondWindow(QtWidgets.QDialog, FORM_CLASS):
    def __init__(self, myInput, parent=None):
        super(MySecondWindow, self).__init__(parent)
        self.setupUi(self)

        self.myInfoClass = myInput
        self.myData = self.dynamicallyChangeLabel()
        self.dynamicallyChangeLabel()

    def dynamicallyChangeLabel(self):
        print("Checking label value")
        if self.myInfoClass.myInfoAttribute != None :
            self.myLabel.setText(self.myInfoClass.myInfoAttribute)

It seems the dynamicallyChangeLabel is not even called, since there is no print in my console.

Does anyone have an idea how to do this?

1
  • Is the self.myInfoClass.myInfoAttribute variable entered by the user through the plugin window? If yes, you can connect the input event to the label update. Apr 2, 2023 at 16:54

1 Answer 1

1

In the end I used the showEvent method : it is called right away, without waiting for a user action.

def showEvent(self,showEvent):
        self.fillComboBox()

It is very useful !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.