Thanks in advance. I have just come to realize that there is a bug in a bunch of my python scripts when on Rocky. Previously, all was working as expected on mac or centos. Any of them that spawn a secondary window to save a preset, once the preset is confirmed or cancelled, the main window goes behind the Flame app. You have to alt + tab away, then back to get it visible again. For example, this occurs in Find Replace in Name Advance.
To try to whittle this down, Ive created some most basic examples.
pyside_example_qwidget = shows the problem in the most basic way. once you click the save button to the secondary window, closing that window causes the main window to go under Flame.
pyside_example_alwaysontop = then i thought i should try always on top hints for all windows. this allllllmost works… but then the secondary save window always spawns under the main window.
pyside_example_qdialog = i thought maybe i should try making the main window a QDialog as well. i think fundamentally these scripts should be always on top & modal/blocking like a QDialog. the only thing is that whatever blocking signal its sending to Flame is causing the cursor to be the fish icon instead of the regular. soo i feel this method is breaking conventions. an artist might think Flame has locked up. if i could sort the cursor, I thiiiink this is the most proper way.
So to conclude… Im deep in the weeds here. Wondering if anyone has else has already conquered this issue or could enlighten me where my PySide thinking/logic is going wrong. Thanks again.
i spent the last few weeks replacing everything about Logik-Projekt with tkinter, and will soon remove that shit too.
I don’t have any good news for you.
I’m heading towards bash/rust/TUI.
I looked at your pyside_example_qwidget_alwaysontop.py and I think your problem is that the save button is emitting a signal to have the Save Dialog appear, but I think it’s better if the save button calls a member function in the Main Window class and it creates the Save Window object and you call save_window._exec() on it. That way the save window is a child of the Main Window.
I’ve haven’t had the need to use emit() in this fashion for creating new widgets. Is this because you want the window to pop up faster?
The reasons for emit is because im trying to go full MVC with these examples. When I was trying to diagnose this issue on a full on script like Find and Replace in Name Advance, it quickly got unmanageable. My controllers are all mixed in with my views. So trying to disentangle all of it this time. Going with the standard PySide signals and slots. Views (the window classes) separate from the Controller (the main class), and then the Model. The Model isnt represented in the examples yet. self.selection might be sufficient, but probably need a Model for the saved presets.
Find and Replace in Name Advance is already set up as a member function. I mocked up a simpler example below
This is what you are describing right? The main window still gets lost behind the Flame window on Rocky unfortunately.
Thanks for pointing me towards parenting. Im testing that in between renders. So far, setParent() is crashing Flame. Im doing self.save_window.setParent(self.main_window) in the Main.__init__(). Im also experimenting with .raise() on the main_window after the save dialog closes, but no luck yet.
@MikeV had contacted me about trying to dynamically set and unset AlwaysStaysOnTopHint… still need to try that.
Im also seeing that instead of a QDialog, perhaps setting window flags of QtCore.Qt.ToolWindow might what Im after. Just heading in too many directions right now.
Thanks to @DannyYoon and his suggestion to look at parenting. I never got setParent() to work, but setting a parent at creation works. I did this with the super().__init__(parent) inside the SaveWindow.__init__() and then self.save_window = SaveWindow(self.main_window) in the Main class.
In the articles I found, parenting is only set via the below:
passed as an arg at creation
setParent()
or when using addWidget() for layouts
This example now behaves as expected on Rocky & Mac. Woo!
Im planning to use this as my boilerplate for PySide & MVC going forward. Curious if anyone sees anything that could be improved. Thanks in advance.
I don’t use QT enough to remember these kind of subtleties like setting the parent. Because QT is based on C++, they structured it so the widgets handle the memory management automatically but you have to remember to follow certain rules like parent/child relationships.
Have you read this book on QT gui for python?
I highly recommend this book! It’s very clear and does a better job than the QT docs explaining how to use QT.