发布时间:2022-10-14 11:30
我这样做是为了我的WACOM Intoos艺术平板电脑:
只需继承一个QWidget类并定义tabletEvent()方法来处理接收到的QTabletEvent事件。在
别忘了打电话给平板电脑tabletEvent.accept()方法位于处理程序末尾。在
示例:
(处理TabletPress、tabletreease和TabletMove事件)
当笔接触平板电脑表面时,生成TabletPress事件,当笔离开平板电脑表面时生成TabletRelease事件。
在这些事件之间生成一个TabletMove事件流。在
对于每个接收到的QTabletEvent,您将得到笔的位置和笔的压力。(我的平板电脑上没有倾斜信息)
请注意,我不得不将示例窗口调整为完全桌面大小,以便从整个平板电脑表面获取表事件。我不知道如何从平板电脑的所有表面捕捉事件,将其映射到widget客户端表面,如果它没有调整到完全的桌面大小。(对此问题的任何帮助都将得到极大的重视。)import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class TabletSampleWindow(QWidget):
def __init__(self, parent=None):
super(TabletSampleWindow, self).__init__(parent)
self.pen_is_down = False
self.pen_x = 0
self.pen_y = 0
self.pen_pressure = 0
self.text = ""
# Resizing the sample window to full desktop size:
frame_rect = app.desktop().frameGeometry()
width, height = frame_rect.width(), frame_rect.height()
self.resize(width, height)
self.move(-9, 0)
self.setWindowTitle("Sample Tablet Event Handling")
def tabletEvent(self, tabletEvent):
self.pen_x = tabletEvent.globalX()
self.pen_y = tabletEvent.globalY()
self.pen_pressure = int(tabletEvent.pressure() * 100)
if tabletEvent.type() == QTabletEvent.TabletPress:
self.pen_is_down = True
self.text = "TabletPress event"
elif tabletEvent.type() == QTabletEvent.TabletMove:
self.pen_is_down = True
self.text = "TabletMove event"
elif tabletEvent.type() == QTabletEvent.TabletRelease:
self.pen_is_down = False
self.text = "TabletRelease event"
self.text += " at x={0}, y={1}, pressure={2}%,".format(self.pen_x, self.pen_y, self.pen_pressure)
if self.pen_is_down:
self.text += " Pen is down."
else:
self.text += " Pen is up."
tabletEvent.accept()
self.update()
def paintEvent(self, event):
text = self.text
i = text.find("\n\n")
if i >= 0:
text = text.left(i)
painter = QPainter(self)
painter.setRenderHint(QPainter.TextAntialiasing)
painter.drawText(self.rect(), Qt.AlignTop | Qt.AlignLeft , text)
app = QApplication(sys.argv)
mainform = TabletSampleWindow()
mainform.show()
app.exec_()
2022届秋招,从被拒到上岸 | 谈谈YK菌在2021年的经历与收获
【canvas教程】实现画布拖动、定点缩放,支持手势与鼠标滚轮操作
在centos docker中封装flask应用,并使用命令和dockerfile两种方式制作镜像实战
告别shiro-cas单点登录集成库,这款简单且强壮的Java Web安全引擎pac4j你值得拥有
electron打包报错permission denied, rmdir '/tmp/electron-packager'
Bert+LSTM+CRF命名实体识别pytorch代码详解
Python项目实战(一)《Python编程 从入门到实践》
opencv(12):cv::rectangle学习与代码演示,使用opencv画矩形/矩形框
android 即时聊天源码websocket,基于WebSocket实现的Android和H5聊天通讯实例【附效果图附所有源码】使用的源码...