Issue
I create a main window use QT ui window file and I want to click menu pop another ui window. this is second window, and after close, the main window will get focus and get data from second window.
How can i do this?
I search internet and find convert ui file to py file, use as class. Actually i will change window, in QT designer, So i down't want change to py file.
Solution
To switch between two windows based on .ui
files in a PyQt application without converting the .ui
files to .py
files, you can use the uic
module to load the .ui
files dynamically. This way, you can easily make changes in Qt Designer and see them reflected in your application without needing to regenerate Python files.
from PyQt5 import QtWidgets, uic
from PyQt5.QtWidgets import QApplication
import sys
def open_second_window():
second_window.show()
data_from_second_window = second_window.findChild(QtWidgets.QLineEdit, 'lineEdit')
# Do something with data_from_second_window if needed
def close_second_window():
# Get data from second_window if needed
second_window.hide()
main_window.show()
app = QApplication([])
main_window = uic.loadUi("main_window.ui")
second_window = uic.loadUi("second_window.ui")
# Connect menu action to open the second window
main_window.actionOpenSecondWindow.triggered.connect(open_second_window)
# Connect a button in the second window to close it and return to the main window
second_window.pushButton.clicked.connect(close_second_window)
main_window.show()
sys.exit(app.exec_())
Answered By - murat taşçı
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.