PDA

View Full Version : Qt Creator: connecting actions trigged to slots



ecce
19th April 2016, 20:45
I've started a small project in PyQt5. I've used Qt Creator to design the UI for the Main Window, and converting the .ui file by using the pyuic5 tool for use with my python code, which I write in PyCharm. It worked fine for a couple of days, but I ran into a bit of trouble when I added toolbar buttons. So first things first:

- Is Qt Designer nowadays built-in Qt Creator, or am I using the wrong application? (there a lot of instructions to use Designer everywhere on the web, I can't find it)

I ran into trouble when I wanted to connect an action for a toolbar button to a slot. I can create the action in Qt Creator, but the slot I want to use is not familiar to Qt Creator since it's written in PyCharm, outside the project from Qt Creators point of view. The slot is in the MainWindow class, but Qt Creator does not know that and I can't select it from the drop down list. Any suggestions?

anda_skoa
19th April 2016, 20:58
I
- Is Qt Designer nowadays built-in Qt Creator, or am I using the wrong application? (there a lot of instructions to use Designer everywhere on the web, I can't find it)

It is available both as a stand-alone tool as well as integrated in QtCreator.
Since you are using a different IDE than QtCreator, just keep using the stand-alone version.


I
I ran into trouble when I wanted to connect an action for a toolbar button to a slot. I can create the action in Qt Creator, but the slot I want to use is not familiar to Qt Creator since it's written in PyCharm, outside the project from Qt Creators point of view. The slot is in the MainWindow class, but Qt Creator does not know that and I can't select it from the drop down list. Any suggestions?
Just don't connect in QtDesigner, connect in code.
I would recommend the same thing if you were using C++, btw :)

Cheers,
_

ecce
20th April 2016, 19:22
It is available both as a stand-alone tool as well as integrated in QtCreator.
Where do I find the Qt Designer as a stand alone application? I can find a lot of stuff to download on http://www.qt.io/download-open-source/ but there is no explicit link for the designer as far as I can see.


Just don't connect in QtDesigner, connect in code.
That's what I tried to do first. According to the hierarchy on the top right in QtCreator, I have MainWindow (QMainWindow) ->toolBar (QToolBar) ->actionScan (QAction). So I wrote this line of code:


self.toolBar.actionScan.trigged.connect(scan)

and I got this when I run the code: AttributeError: 'QToolBar' object has no attribute 'actionScan'

anda_skoa
20th April 2016, 20:12
Where do I find the Qt Designer as a stand alone application? I can find a lot of stuff to download on http://www.qt.io/download-open-source/ but there is no explicit link for the designer as far as I can see.

Should be part of the normal Qt installer.
Check the bin directory.



That's what I tried to do first. According to the hierarchy on the top right in QtCreator, I have MainWindow (QMainWindow) ->toolBar (QToolBar) ->actionScan (QAction). So I wrote this line of code:


self.toolBar.actionScan.trigged.connect(scan)

and I got this when I run the code: AttributeError: 'QToolBar' object has no attribute 'actionScan'

All the actions are top level elements themselves, they are then plugged into different UI elements, e.g. toolbars, menus.

Cheers,
_

ecce
21st April 2016, 20:23
OK, I got it working (it hit me I could easily see that by put a debug breakpoint an examine what's going on....)

No trace whatsoever of qt designer as far as I can see... but it does not matter, qt creator works fine.

Thanks!