Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyQt bounding box for graphic design software

License

NotificationsYou must be signed in to change notification settings

yjg30737/pyqt-bounding-box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 inhere)
  • setWidth(width: int)
  • setHeight(height: int)
  • setSize(width: int, height: int)

You can use the standard function likesetPen(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

fromPyQt5.QtWidgetsimportQWidget,QGraphicsView,QVBoxLayout,QApplication,QGraphicsScenefrompyqt_bounding_box.boundingBoximportBoundingBoxclassExample(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__":importsysapp=QApplication(sys.argv)example=Example()example.show()app.exec_()

Result

example.mp4

See Also


[8]ページ先頭

©2009-2025 Movatter.jp