qpainter - PyQt Painter shape as button - Stack Overflow

import sysfrom PyQt6 import QtWidgets, QtGui, QtCoreclass PainterButton(QtWidgets.QWidget):def __init_

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743742835a4499460.html

相关推荐

  • qpainter - PyQt Painter shape as button - Stack Overflow

    import sysfrom PyQt6 import QtWidgets, QtGui, QtCoreclass PainterButton(QtWidgets.QWidget):def __init_

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信