PySide2 Issue with a Button Functionality in Qt Window

   1395   6   1
User Avatar
Member
6 posts
Joined: March 2016
Offline
Hello everyone,

I’m new to Qt and facing an issue while writing in PySide2 for Houdini UI.. I’ve written a script in Houdini that creates a window with two buttons: Build and Close.

Clicking the Build button opens another window with the same two buttons (Build and Close).
The Build button works fine the first time, opening the new window. However, subsequent clicks on the Build button don’t seem to work at all.
Additionally, each click on the Build button is counted, and when the Close button is clicked, it prints the total number of clicks. This behavior happens regardless of whether you close the window from the main or subsequent windows.
Could someone please explain why the Build button stops functioning after the first click? I’d appreciate any help or guidance!
https://github.com/MaheshFXTD/shotbuilder [github.com]

Please note that main.py is for houdini ui and windows_main.py is for running the code in windows python3.1 which works fine. But for some reason it's not working in houdini.
Thank you!
Image Not Found

Image Not Found

Attachments:
main.py (5.7 KB)
windows_main.py (5.4 KB)

User Avatar
Member
109 posts
Joined: Aug. 2017
Offline
I hope I understand you correctly. You can't click it anymore because the second dialog spawned by clicking "Build" is a modal, meaning it's a type of a pop-up that requires user interaction before they're allowed to do anything with the main application again. It is a modal because you launch it with dialog.exec()in the show_collected_files_windowmethod.

If you want to keep the window clickable, use dialog.show()instead.
User Avatar
Member
6 posts
Joined: March 2016
Offline
@alex Thanks for responding on this topic.
Most of the issues in the UI are fixed but still close button or default close button is printing the collected files before closing the window.
I’ve tried using self.close, self.ignore, and overriding the closeEvent function, but the issue persists.
User Avatar
Member
109 posts
Joined: Aug. 2017
Offline
Are you asking me how to stop your program from printing the message "Debugging collected files."? Your close button has a lambda function connected to it (line 138):

build_button.clicked.connect(lambda: print("Debugging collected files.")) 

Remove this line and you're good.
User Avatar
Member
6 posts
Joined: March 2016
Offline
No that's correct, my doubt is about the below line.(line 142)
        close_button.clicked.connect(dialog.reject)  # Use reject to close the dialog

If I press close button that's printing "Debugging collected files." before closing, which I have connected to build button only.
User Avatar
Member
109 posts
Joined: Aug. 2017
Offline
You must still be using a modal dialog.exec()and not dialog.show().

The parent program becomes frozen when launching a modal, and any print statements will also wait until you've closed the window. What you're seeing is not the "Close" button printing anything, but rather (to my understanding) resuming your program and all the print()commands you've accumulated appear all at once -- but they were in fact created by your "Build" button.

Switch to dialog.show()and it will make your Build button print statements the moment you press it and your Close button will not print anything anymore.
User Avatar
Member
6 posts
Joined: March 2016
Offline
That's right. It's working perfectly fine. Thank you so much.
  • Quick Links