Dynamically Updating UI

In general, is there an efficient way to dynamically update the UI? I want to allow the user to enter in a value in a text field (QLineEdit), hit a button, and update a separate field (I’m using QLabel) in the UI to reflect that change (in addition to performing some other logic which I have yet to implement). However, I noticed sometimes there is lagging. If I merely print this new value to the python interactor, it basically occurs instantly. However, updating the UI takes more than 10 seconds sometimes.

This shouldn’t take so long, can you post your code here?

Excuse me if any of this is bad practice as I am still learning how to create a module. Here is the portion of the code for this UI update:

widget = slicer.util.loadUI(“filepath”)
self.layout.addWidget(widget)
self.ui = slicer.util.childWidgetVariables(widget)

And then in the function that is tied to the button:
newValue = self.ui.newField.text
self.ui.oldValue.setText(newValue)
self.ui.newField.setText("") (to clear the new field once the user hits the button)

Also not sure if this is relevant and maybe this is affecting the performance, but I created multiple .ui files to use in my module for organizational purposes. Should I only be using 1 or does it not matter?

I don’t see anything that would cause the label to not update, so it could be the structure. You can see how it should work with a simple example:

def onToggle():
  str = input.text
  label.setText(str)
  input.setText("Input")

menu = ctk.ctkCollapsibleButton()
menuLayout = qt.QFormLayout(menu)
input = qt.QLineEdit('Input')
label = qt.QLabel("UI Label ")
b=qt.QPushButton('Toggle') 
b.connect('clicked()',onToggle)

menuLayout.addWidget(input)
menuLayout.addWidget(label)
menuLayout.addWidget(b)
menu.show()

Would you recommend that I use pyqt? I’ve seen several tutorials reference it, but the original tutorial I used didn’t utilize it so I didn’t either.

Doing some like a=qt.QPushButton() is already the python interface that you can use in Slicer to interact with Qt which is C++ based. Slicer uses PythonQt and not PyQt. They are similar in syntax, but with different licensing.

How are you currently connecting the button press to updating the label?
I generally connect actions using the newer style of

a=qt.QPushButton()
a.clicked.connect(slotName)

I’ve read conflicting information on the best practice, but I’ve used the Qt Designer to create my widgets and then reference them within the python file.

As far as the button press, I was using a tutorial on laplace transformations from the Slicer site as a reference which had used a button in the following code

laplaceButton.connect(‘clicked(bool)’, self.onApply)

However, I can’t seem to find the documentation for “connect” for QPushButton. Would you mind pointing me towards the API/documentation for QPushButton, specifically the part that mentions using “clicked” and “connect”? I’ve searched and can’t find it that references those two.

Aren’t those C++? I’m looking for python.

The documentation on how they perform are the same. Are you instead looking for python syntax? If so you can use pyqt documentation as a basis since it is similar to pythonqt but not exactly the same.

Right, I was looking for python syntax. But thank you. I’ll do that then.