平板python_Wacom平板电脑的Python示例

发布时间:2022-08-19 11:29

我这样做是为了我的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_()

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号