最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

qpainter - PyQt Painter shape as button - Stack Overflow

programmeradmin0浏览0评论
import sys
from PyQt6 import QtWidgets, QtGui, QtCore

class PainterButton(QtWidgets.QWidget):

    def __init__(self):
        super().__init__()

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(QtGui.QPen(QtCore.Qt.GlobalColor.blue, 5))
        painter.setBrush(QtGui.QBrush(QtCore.Qt.GlobalColor.gray))
        painter.drawRect(20,20,300,300)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = PainterButton()
    w.show()
    sys.exit(app.exec())

I'm new in pyqt. How can use a drawed shape using pyqt qpainter as a button, so i want when mouse cursor is on it, its color to be changed. how can i do it?

How can change qpainter color when mouse is over it? thanks for any suggesions

发布评论

评论列表(0)

  1. 暂无评论