Giter Club home page Giter Club logo

pyqt-hidable-menubar's Issues

How to implement a custom menu for selecting and dragging shapes from there to QGraphicsView for a graphic editor?

``I am trying to implement a graphic editor. As a canvas for drawing, I use QGraphicsScene together with QGraphicsView.

There was a problem with the implementation of the panel, which is essentially a menu of shapes, from where it would be possible to drag shapes to QGraphicsView. It is located outside of QGraphicsView.
I would also like this menu to be divided into several sections so that they can be opened and closed by a button.

Is there an example of implementing this custom shapes menu? Or maybe thoughts with which it can be implemented?

This gif is the example of how I would like it to work (I use drawio as an example):
Shape_menu

My code:
`from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys

window class

class Window(QMainWindow):
def init(self):
super().init()

    wid = QWidget()
    self.setCentralWidget(wid)

    # setting title
    self.setWindowTitle("Paint with PyQt5")

    # setting geometry to main window
    self.setGeometry(100, 100, 800, 600)


    # Defining a scene rect of 400x200, with it's origin at 0,0.
    # If we don't set this on creation, we can set it later with .setSceneRect
    self.scene = QGraphicsScene(0, 0, 400, 200)

    # Set all items as moveable and selectable.
    for item in self.scene.items():
        item.setFlag(QGraphicsItem.ItemIsMovable)
        item.setFlag(QGraphicsItem.ItemIsSelectable)

    # Define our layout.
    vbox = QVBoxLayout()

    up = QPushButton("Rect")
    up.clicked.connect(self.add_rect)
    vbox.addWidget(up)

    down = QPushButton("Elips")
    down.clicked.connect(self.add_elips)
    vbox.addWidget(down)

    view = QGraphicsView(self.scene)
    view.setRenderHint(QPainter.Antialiasing)

    hbox = QHBoxLayout(self)
    hbox.addLayout(vbox)
    hbox.addWidget(view)

    wid.setLayout(hbox)

def add_rect(self):
    rect = QGraphicsRectItem(0, 0, 200, 50)
    rect.setPos(50, 20)
    rect.setFlag(QGraphicsItem.ItemIsMovable)
    rect.setFlag(QGraphicsItem.ItemIsSelectable)
    self.scene.addItem(rect)

def add_elips(self):
    ellipse = QGraphicsEllipseItem(0, 0, 100, 100)
    ellipse.setPos(75, 30)
    ellipse.setFlag(QGraphicsItem.ItemIsMovable)
    ellipse.setFlag(QGraphicsItem.ItemIsSelectable)
    self.scene.addItem(ellipse)

create pyqt5 app

App = QApplication(sys.argv)

create the instance of our Window

window = Window()

showing the window

window.show()

start the app

sys.exit(App.exec())`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.