PDA

View Full Version : emit a signal into an MdiSubWindow



Qtdigitex
17th July 2016, 19:54
Hello , i'm using pyqt 4 and i have a issue with signals

i'm trying to send a signal into an QmdiSubWindow , from my QMainWindow whenever a button is checked to tell the QMdiSubWindow that it has been checked ,
so the way i proceed is like this :

in my QMainWindow : i connect the signal to a fonction :


self.connect (self.moveButton , SIGNAL("clicked()") , self.send_move_signal)

My send_move_Signal method :


def send_move_signal(self):
self.moveButton.setChecked(True)
self.mdiArea.activeSubWindow().emit ( SIGNAL("moveButton_activated"))


and in the constructor of my Mdi-Widget i proceed like that :


class MdiWid ( QWidget , Ui_SubMdiWindow):
def __init__(self,parent=None):
super(MdiWid,self).__init__(parent)
self.connect (self , SIGNAL("moveButton_activated"),self.updateMoveState)

def updateMoveState(self):
self.moveButton_activated = True

But it doesn't work , and i don't see why :confused::confused:

Any help please ,

anda_skoa
17th July 2016, 20:21
Why so complicated?

Why not just call updateMoveState directly from send_move_signal?

Cheers,
_

Qtdigitex
17th July 2016, 20:39
Thanks for your answer ,

I just started learning to make Mdi Apps ,

so, yes my solutions might be complicated :D

how can i do it ??

I tried this :


def send_move_signal(self):
currentMdi = self.mdiArea.activeSubWindow()
currentMdi.updateMoveState()

But Got error : " QMdiSubWindow " has no attribute updateMoveState

If i created an instance to the last opened MdiSubWindow it will work only on the last one but i want this signal to act on the current active Window

Thanks,

anda_skoa
17th July 2016, 22:27
Ah, I would have assumed that Python's duck typing would recognize the method in your subclass.

Then, how about this:
- connect the button to all MdiWid instances
- inside updateMoveState() you check if this is the active window. If yes you do something, if not you ignore the method call

Cheers,
_

Qtdigitex
18th July 2016, 21:24
- connect the button to all MdiWid instances
_

i don't create an instance for each Opened MdiSubWindow , and i think we must not do it.

The main problem here for me is to acess to the Currently Active Mdi Widget Methods ..

anda_skoa
18th July 2016, 22:55
i don't create an instance for each Opened MdiSubWindow , and i think we must not do it.

That doesn't make any sense.

You have an instance of your sub window class for every sub window.
A window that doesn't exist isn't there at all.



The main problem here for me is to acess to the Currently Active Mdi Widget Methods ..

In C++ that would be a cast, look for whatever mechanism Python uses for such type conversions.

Cheers,
_

Qtdigitex
18th July 2016, 23:10
here's the function that load the document ( QWidget ) :


def load(self):
ImageProject = OIWid()
self.mdiArea.addSubWindow(ImageProject)

i skipped details , but that's it. it's the code that load my widget.

if i make ImageProject an instance variable of my main class ( QMainWindow ) : self.ImageProject instead of ImageProject,

the last opened Project would be self.ImageProject and not the current active window !

anda_skoa
19th July 2016, 01:32
In you first post you had a class MdiWid, but I can't see that being used in your newest code snippet.

Cheers,
_

Qtdigitex
19th July 2016, 13:37
Hi , i finaly found the solution :

i only needed to use the QMdiSubWindow's method : widget() to be able to acess my currently opened widget's methods and signals ...

SO it will become :

self.mdiArea.activeSubWindow().widget().update_mov e_state()

instead of :

self.mdiArea.activeSubWindow().update_move_state()