当前位置:网站首页>pyqt5 pyside2

pyqt5 pyside2

2022-06-09 09:33:00 why151

Direct import ui

from PySide2.QtUiTools import QUiLoader
import sys
from PyQt5.QtWidgets import QApplication

ui_file = QFile("test.ui")
ui_file.open(QFile.ReadOnly)

app = QApplication(sys.argv)
loader = QUiLoader()
window = loader.load(ui_file)
window.show()
sys.exit(app.exec_())

Show interactive pictures

from PySide2.QtGui import QImage, QPixmap
from PySide2.QtUiTools import QUiLoader
from PyQt5.QtWidgets import QApplication, QGraphicsView
from PySide2.QtWidgets import QGraphicsScene, QGraphicsPixmapItem
import sys
import cv2 as cv

app = QApplication(sys.argv)
map = QUiLoader().load('test.ui')
'''  Start introducing pictures to create scenes  '''

pix = QPixmap('school.jpg')
#  Create pixel primitives 
item = QGraphicsPixmapItem(pix)
scene = QGraphicsScene()
scene.addItem(item)
map.show_school.setScene(scene)

map.show()
sys.exit(app.exec_())

Obtain the coordinates of image points and mark them in the image

Mainly want to change the mouse cursor style , After selecting a point, the mouse cursor style is restored and the position of the point is returned .
I have searched the Internet for a long time , Most of the posts you see are about rewriting classes , However, I don't know how to cook , Finally, I found the implementation method .

#  Set up scene
        pix = QPixmap('school.jpg')
        self.item = QGraphicsPixmapItem(pix)
        self.scene = QGraphicsScene()
        self.scene.addItem(self.item)
        self.img.show_school.setScene(self.scene)
        
   def find_begin(self):
   		#  Set the mouse cursor style 
        pix_begin = QPixmap('start.png')
        pix_begin = pix_begin.scaled(60, 60, QtCore.Qt.KeepAspectRatio)
        #  Set the focus position of the mouse cursor 
        cursor = QCursor(pix_begin, 30, 59)
        self.img.show_school.setCursor(cursor)
        #  Set mouse click events 
        self.item.mousePressEvent = self.get_start
        if self.if_find_start != -1:
            self.scene.removeItem(self.pix_begin)
        self.if_find_start = 1
    def get_start(self, event):
        if self.if_find_start == 1:
            self.if_find_start = 0
            pos = event.pos()
            self.start = (Node) (int(pos.x()//25), int(pos.y()//25), 0, 0, None)
            pix_begin = QPixmap('start.png')
            pix_begin = pix_begin.scaled(60, 60, QtCore.Qt.KeepAspectRatio)
            self.pix_begin = QGraphicsPixmapItem(pix_begin)
            self.pix_begin.setPos(pos.x()-30, pos.y()-59)
            self.scene.addItem(self.pix_begin)
            #  Restore the mouse cursor to the original arrow cursor 
            self.img.show_school.setCursor(Qt.ArrowCursor)

Nice style

There are two that can be referenced python Style sheets in the library
Click to see
One more dalao Handwritten super nice pages
Click to see

原网站

版权声明
本文为[why151]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090908004158.html