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?

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Mar 29, 2023 at 7:04
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. Commented 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 !

answered Apr 14, 2023 at 15:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.