I am trying to hide a UI and then show one, but I can't get or hide()
or show()
to work.
My current code looks like this:
import crys.main.ui.mainmenu as w
import crys.main.ui.editor as e
w.Window().hide()
self.ui.hide()
e.Window().show()
The editor I want to open
from PyQt6.QtWidgets import *
import crys.main.helper as h
class Window(QWidget):
def __init__(self):
super().__init__()
print("Booting editor...")
self.setWindowTitle(h.translate("window.editor"))
self.setFixedSize(100, 100)
a = QLabel(self)
a.setText("cool")
self.setStyleSheet(h.get_theme())
and the main menu
class Window(QWidget):
def __init__(self, should_build_ui: bool = False):
super().__init__()
self.buttons = []
self.setStyleSheet(h.get_theme())
self.setWindowTitle(h.translate("window.main"))
self.setFixedSize(960, 540)
if should_build_ui:
self.build_ui()
self.ui
is dialog (QWidget), and the w.Window()
is a main menu. I expected that e.Window().show
the editor window would show, but it didn't. It does hide the self.ui
.
w.Window().show()
will just create an instance that is being immediately destroyed (do some research about garbage collection and variable scope). You probably have to create a persistent reference to an instance and callshow()
for it, but in order to be able to help you, you need to provide a valid minimal reproducible example for your first code, as right now that portion is insufficient and meaningless.