我是PyQt5的新手。我正在尝试在跟踪鼠标的已加载图像线的顶部绘制图像,即,按下鼠标键将导致绘制您鼠标移动到的位置,同时仍然按下鼠标,并且在我们释放鼠标时停止绘制。>
我看到了This answer,它非常有用,但是我正在尝试做一些更复杂的事情。
我想我正在弄乱这些事件。
我写的(不起作用):
import sys
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
from PyQt5.QtGui import QPixmap, QPainter, QPen
class Menu(QMainWindow):
def __init__(self):
super().__init__()
self.drawing = False
self.lastPoint = QPoint()
self.image = QPixmap("picture.png")
self.setGeometry(100, 100, 500, 300)
self.resize(self.image.width(), self.image.height())
self.label = QLabel(self)
self.show()
def paintEvent(self, event):
painter = QPainter(self)
painter.drawPixmap(self.rect(), self.image)
pen = QPen(Qt.red, 3)
painter.setPen(pen)
painter.drawLine(self.lastPoint, event.pos())
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.drawing = True
self.lastPoint = event.pos()
def mouseMoveEvent(self, event):
if event.buttons() and Qt.LeftButton and self.drawing:
painter = QPainter(self.image)
painter.setPen(QPen(Qt.red, 3, Qt.SolidLine))
self.lastPoint = event.pos()
self.update()
def mouseReleaseEvent(self, event):
if event.button == Qt.LeftButton:
self.drawing = False
if __name__ == '__main__':
app = QApplication(sys.argv)
mainMenu = Menu()
sys.exit(app.exec_())
答案 0 :(得分:2)
您要在var express = require('express');
var router = express.Router();
var controller = require('../controllers/coursescontroller');
router.get('/', function(req, res, next) {
var records = controller.find_records();
console.log(records); // console shows undefined
res.send(records); // doesn't send anything back when I make a get request
});
中使用drawLine
。当您移动鼠标时,它将调用mouseMoveEvent
,它将从最后一个位置开始绘制一条线,然后它将自行调用mouseMoveEvent
。
尝试一下:
paintEvent