How to use QMdiSubWindow classes ?
i'm using pyqt4 and trying to make an MDI little application :
i have two script : the main one inherits from QMainWindow and the second one that inherits from QWidget : it represents the type of document my application open each time i click on Open.
i'm having trouble about two issues :
How to send a signal from my main script to the CURRENTLY ACTIVE Widget ( even if i opened several documents ) in order to run a method that's inside the widget class ( opened document ) ?
Isn't it possible to run the methods inside my Widget class whithout sending a signal ?
I tried this :
self.actualWidget = self.mdiArea.activeSubWindow() self.actualWidget.test_method() # test_method is just for testing if it will run
i always get the error message :
AttributeError : 'QMdiSubWindow' has no attribute 'test_method'.
it's just as if activeSubWindow() returns a QMdiSubWindow instead of my CURRENTLY ACTIVE Widget ...
Any Help please ? !
@QtDigitex For me it is not clear how you use your QWidget derived class as MDI sub window? If you put your QWidget class in a QMdiSubWindow then you have to get it from there first and then call your methods.
yes , i don't know how to do it , it's my first time . this is what i did :
i made the design of both ( Main window & documents window ( it's a QGraphicsView +
QTableWidget for each opened file ) )Via QtDesigner , so i choosed to create a QWidget ( there's no QMdiSubWindow ) and got the py code via pyuic4.
in my secondary class i wrote :
class Window_Widget ( QWidget , Ui_Form) : # Since i choosed in QtDesigner to create a QWidget and it's name is Form ( the Ui_Form class is issued from pyuic 4 )
i think the problem comes from here , because if i change QWidget to QMdiSubWindow , the signals works greatly but the design and layouts that i made in QtDesigner breaks down ...
Hi Normally , you talk to the widget you have inside the mdi window.
If using a plain MDIwindow, then you insert your widget with
and get with widget()
And then cast to the correct type to call functions.
Alternative you derive from QMdiSubWindow and expand with new functions.
Thank you so much ,
all the problem comes from not accessing the widget Inside my QmdiSUbWindow , the widget() method resolved the problem. Now it works perfectly , thanks.
But , can you please detail your second method , you mean that my secondary class must inherits QMdiSubWindow like this ? :
class Widget_Window ( QMdiSubWindow , Ui_Form):
the problem is that i made the design with QtDesigner and the code like this breaks all the layouts and the display. However , signals work
uhh, Im python noob :)
so not sure about syntax.
in c++, it would be
class MyMDI : QMdiSubWindow
Then the actual MDIsubWindow would be your type and could have extra functions.
You would then have to new MYMDI and give to the Area with
and when using activeSubWindow, you would cast to myMDI type and call functions.
( talking c++, python ,might allow something else :)