Python Forum
[PyQt] Create Node via ToolbarButtonClick
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Create Node via ToolbarButtonClick
I'm new here and I'm hoping that you can help me a little bit here. Angel
I work with Python 3.7, pyqt 5.13.2 and windows 8, if that is important.
I also did some reading about toolbars, but that didn't really help me with my problem so far.

My problem is that I want to create a box via toolbar click, which appears in my graphical scene with a button click. Creating the toolbar wasn't that difficult now, but I don't know how to write the function that creates the box.

At the moment I have three boxes loaded at the start of the program, but later I want to go over to the fact that they can only be added via the toolbar click. To simplify things, they should be created in the middle of the scene so Position(0,0).
However, i think i am barking up the wrong tree and sadly I can't get a proper function Wall .
Since Iam a beginner please have mercy Pray .
Here is my code I use... it is actually much bigger, but I cut it down to make it not so confusing, but even now its quiet long. Shifty
The funktion i am looking for is def addnewBox in in line 41, I just put a "?" because i dont how to do it at all:(

The Picture addBox.png for the toolbar in editor_window line 36 is from the website with the name note_add.
From here:

stay healthy in these times Angel

Actualy I found a mistake in the imports
in it is
from editor_graphics_scene import GraphicsScene
in it is
from editor_main_widget import MainWidget
from editor_scene import Scene
from editor_box import Box

sorry for that Wall
If you put print("addnewbox called") inside the addnewbox method do you see anything when you press the toolbar button?
When i make it like this:

    def createToolBars(self):
        # initialize toolbar
        toolbar = QToolBar("my main toolbar")
        toolbar.setIconSize(QSize(32, 32))
        button_action = QAction(QIcon("addBox.png"), "New box 1", self)
        button_action.setStatusTip("Add a new Box")

    def addnewBox(self):
        print("addnewbox called")
I get an error:

File "C:\Users\Sebastian\PycharmProjects\TUProject\tests\testtoolbar\", line 38, in createToolBars button_action.triggered.connect(self.addnewBox()) TypeError: argument 1 has unexpected type 'NoneType'

I forgot to delete the bracket () behind the self.addnew Box:
And now i get my output when i press the button
addnewbox called
so this works:)

currently the editor looks like this:[email protected]/
I uploaded a screenshot on

Possibly Related Threads…
Thread Author Replies Views Last Post
  Treeview - SQL - Add child node snakes 0 242 May-15-2021, 08:48 PM
Last Post: snakes

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020