What you try at the end is the correct way to do it. The only weird thing I see is
window_vt = QMdiSubWindow(self.win_vt) that should be
window_vt = QMdiSubWindow() . If not, the cause of not working for you may be due to name conflict. Keep in mind that just as it is
window_norm are local variables to the method where you define them. If you use
self.mdiArea.setActiveSubWindow(window_ts) outside of that method it will not work logically. On the other hand, using the same name for the instances of your widgets and for those of
QMdiSubWindow can be confusing and even lead to errors. You should see your entire app or at least the error it sends you (if it does).
That said, I'll explain a bit how to do it and give a reproducible example to show its use.
You must create
QMdiarea , then add the widgets you want to each subwindow as if it were any other window (as we would in a
QMainWidget for example).
setActiveSubWindow method must receive an instance of
QMdiSubWindows in all cases.
In the following example, three windows are created and we place the focus on the second one that is created. Each window has a
QTextEdit inside, this is only as an example and so that they are not empty windows. It would be the same for any other frame.
from PyQt4.QtGui import QApplication, QMainWindow, QMdiSubWindow, QMdiArea, QTextEdit
def __init__(self, parent = None):
self.mdi = QMdiArea()
self.win_ts = QMdiSubWindow()
self.win_vt = QMdiSubWindow()
self.win_norm = sub = QMdiSubWindow()
self.mdi.cascadeSubWindows() # Ordena las ventanas en cascada
app = QApplication(sys.argv)
ex = MainWindow()
if __name__ == '__main__':
What should produce something like:
We can see how the focus appears in the second window (
self.win_vt ) as we wanted.