Skip to content

Commit 8e84f03

Browse files
committed
Dropdown for add button
1 parent a47c3ef commit 8e84f03

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

editor/views.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
2-
from PyQt5.QtCore import QSize
3-
from PyQt5.QtGui import QIcon, QPixmap
2+
from PyQt5.QtCore import Qt
3+
from PyQt5.QtGui import QIcon
44
from PyQt5.QtWidgets import *
55

66
class HierarchyItem(QTreeWidgetItem):
@@ -30,12 +30,22 @@ def __init__(self, parent):
3030
self.vbox_layout.setSpacing(2)
3131

3232
self.hbox_layout = QHBoxLayout()
33-
self.hbox_layout.setStretch(0, 1)
34-
self.hbox_layout.addWidget(QLabel("Untitled Scene"))
33+
# self.hbox_layout.setStretch(0, 1)
34+
self.title = QLabel("Untitled Scene")
35+
self.hbox_layout.addWidget(self.title)
36+
3537
self.add_button = QToolButton(self)
3638
self.add_button.setIcon(QIcon(os.path.join(os.path.dirname(
3739
os.path.abspath(__file__)), "icons", "inspector", "add.png")))
3840
self.add_button.setStyleSheet("padding: 3px;")
41+
self.add_button.setPopupMode(QToolButton.InstantPopup)
42+
self.add_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
43+
44+
self.menu = QMenu()
45+
self.menu.addAction("New GameObject")
46+
self.menu.addAction("New Child GameObject")
47+
self.add_button.setMenu(self.menu)
48+
3949
self.hbox_layout.addWidget(self.add_button)
4050
self.vbox_layout.addLayout(self.hbox_layout)
4151

@@ -64,9 +74,10 @@ def add_item_pos(self, gameObject, *args):
6474
parent = parent.children[num]
6575
parent.add_child(item)
6676
return item
67-
77+
6878
def load_scene(self, scene):
6979
self.loaded = scene
80+
self.title.setText(scene.name)
7081
items = {}
7182
for gameObject in self.loaded.rootGameObjects:
7283
items[gameObject] = self.add_item(gameObject)

0 commit comments

Comments
 (0)