如何在PyQt5中更改光标大小?

huangapple go评论68阅读模式
英文:

How to change cursor size in PyQt5?

问题

我想实现像大多数图像编辑器中的画笔光标,当光标是一个圆圈时,根据画笔大小改变其大小。我已经阅读了文档,并只找到了setShape方法,但没有setSize。在Qt中是否可以更改光标大小?

英文:

I want to implement brush cursor like in most image editors when cursor is a circle that change its size according to brush size. I've read the docs and found only setShape method, but no setSize. Is it possible in Qt to change cursor size?

答案1

得分: 1

pixmap = QPixmap("image.png") # 替换为您自定义光标图像的路径,刷子在您的情况下
pixmap = pixmap.scaled(30, 30) # 设置所需的大小
cursor = QCursor(pixmap)
self.setCursor(cursor)

您可以通过创建一个 pixmap,然后将其分配给光标,在 PyQt5 中更改光标的大小和 "形状"。

英文:
pixmap = QPixmap("image.png")  # Replace with the path to your custom cursor image, brush in your case
pixmap = pixmap.scaled(30, 30)  # Set the desired size
cursor = QCursor(pixmap)
self.setCursor(cursor)

you can change the size and the "form" of your cursor in PyQt5 by creating a pixmap and then assigning in to your cursor

huangapple
  • 本文由 发表于 2023年6月1日 19:23:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定