Giter Club home page Giter Club logo

pyqt-bounding-box's Introduction

pyqt-bounding-box

PyQt bounding box for graphic design software

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-bounding-box

Feature

  • Cursor shape changes properly for position (horizontal/vertical edge, etc.)
  • Being able to resize the box horizontally/vertically/diagonally
  • Being able to move the box with either mouse cursor or arrow keys
  • Being able to change the attribute of the box

Methods Overview

  • setLineWidth(self, n: int) - Default width is 3
  • setColor(self, color: QColor) - Default color is black
  • setStyle(self, style: Qt.PenStyle) - Default style is Qt.DashLine (You can see more about this style in here)
  • setWidth(width: int)
  • setHeight(height: int)
  • setSize(width: int, height: int)

You can use the standard function like setPen(pen: QPen) if you know how to use it, Here's the example:

item = BoundingBox()

pen = QPen()
pen.setStyle(Qt.DashLine)
pen.setWidth(3)
pen.setColor(QColor(0, 0, 0))

item.setPen(pen)

Example

Code Sample

from PyQt5.QtWidgets import QWidget, QGraphicsView, QVBoxLayout, QApplication, QGraphicsScene

from pyqt_bounding_box.boundingBox import BoundingBox


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        view = QGraphicsView()
        self.__scene = QGraphicsScene()
        self.__scene.setSceneRect(0, 0, 400, 400)

        item = BoundingBox()
        # item.setLineWidth(8) If you want to change the edge line width, add the code.
        # item.setColor(QColor(255, 255, 255)) If you want to change the color of the line to white, add the code.
        # item.setStyle(Qt.SolidLine) If you want to change the style of line from dashed to solid line, add the code.
        self.__scene.addItem(item)
        view.setScene(self.__scene)

        lay = QVBoxLayout()
        lay.addWidget(view)

        self.setLayout(lay)


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    example = Example()
    example.show()
    app.exec_()

Result

example.mp4

See Also

pyqt-bounding-box's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.