Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [PyQt] Create Node via ToolbarButtonClick
#1
Hi!
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 editor_window.py 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 material.io with the name note_add.
From here:https://material.io/resources/icons/?ico...e=baseline

stay healthy in these times Angel



editor_main.py
editor_window.py
editor_scene.py
editor_graphics_scene.py
editor_box.py
editor_graphics_box.py
editor_graphics_view.py
editor_content_widget.py
editor_main_widget.py

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

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

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

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

Error:
File "C:\Users\Sebastian\PycharmProjects\TUProject\tests\testtoolbar\editor_window.py", 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:
button_action.triggered.connect(self.addnewBox)
And now i get my output when i press the button
Output:
addnewbox called
so this works:)

currently the editor looks like this:

https://www.flickr.com/photos/147301383@...700842872/
I uploaded a screenshot on flickr.com:)
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)