connecting clicked signal to different slots depending on function executing


T

tausciam

I have one tablewidget I want to use for two different uses, audio and video. If cover art is displayed and the user clicks the cover art, it emits a cell clicked and gets the list of the songs. If video thumbnails are displayed, it emits a cell clicked and plays the video fullscreen.

So, I have the same signal going to two different slots. Is there any way to break that connection before I define it again? In other words, in the audio section I could have something like:

[break video signal/slot connection]
self.tableWidget.cellClicked.connect(self.audiocell_clicked)

and then for the video section:

[break audio signal/slot connection]
self.tableWidget.cellClicked.connect(self.videocell_clicked)
 
Ad

Advertisements

T

tausciam

I should add that I know about:

self.tableWidget.cellClicked.disconnect(self.videocell_clicked)

but, when I do that, if the connection is not there, then the program crashes. So, how could I check to see if the connection is there then break it?
 
Ad

Advertisements

T

tausciam

Nevermind..... I found that it would let me create the connection again then when I disconnected, it would disconnect all of the instances...

so I ended up with:

self.tableWidget.cellClicked.connect(self.videocell_clicked)
self.tableWidget.cellClicked.disconnect(self.videocell_clicked)
self.tableWidget.cellClicked.connect(self.audiocell_clicked)

If there's a better way to do this, I'd be interested in hearing about it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top