**pyqt_example_learn<wiggly>

 
  
// from pyqt_examples
from
PyQt4 import QtCore, QtGui


class WigglyWidget(QtGui.QWidget):
def __init__ (self, parent = None):
super(WigglyWidget, self).
__init__ (parent)

self.setBackgroundRole(QtGui.QPalette.Midlight)
self.setAutoFillBackground(True)

newFont
= self.font()
newFont.setPointSize(newFont.pointSize()
+ 20 )
self.setFont(newFont)

self.timer
= QtCore.QBasicTimer()
self.text
= ''

self.step
= 0;
self.timer.start(
60 , self)

def paintEvent(self, event):
sineTable
= (0, 38 , 71 , 92 , 100 , 92 , 71 , 38 , 0, - 38 , - 71 , - 92 , - 100 , - 92 , - 71 , - 38 )

metrics
= QtGui.QFontMetrics(self.font())
x
= (self.width() - metrics.width(self.text)) / 2
y
= (self.height() + metrics.ascent() - metrics.descent()) / 2
color
= QtGui.QColor()

painter
= QtGui.QPainter(self)

for i, ch in enumerate(self.text):
index
= (self.step + i) % 16
color.setHsv((
15 - index) * 16 , 255 , 191 )
painter.setPen(color)
painter.drawText(x, y
- ((sineTable[index] * metrics.height()) / 400 ), ch)
x
+= metrics.width(ch)

def setText(self, newText):
self.text
= newText

def timerEvent(self, event):
if event.timerId() == self.timer.timerId():
self.step
+= 1
self.update()
else :
super(WigglyWidget, self).timerEvent(event)


class Dialog(QtGui.QDialog):
def __init__ (self, parent = None):
super(Dialog, self).
__init__ (parent)

wigglyWidget
= WigglyWidget()
lineEdit
= QtGui.QLineEdit()

layout
= QtGui.QVBoxLayout()
layout.addWidget(wigglyWidget)
layout.addWidget(lineEdit)
self.setLayout(layout)

lineEdit.textChanged.connect(wigglyWidget.setText)

lineEdit.setText(
" Hello world! " )

self.setWindowTitle(
" Wiggly " )
self.resize(
360 , 145 )


if __name__ == ' __main__ ' :

import sys

app
= QtGui.QApplication(sys.argv)
dialog
= Dialog()
dialog.show();
sys.exit(app.exec_())

转载于:https://www.cnblogs.com/eth0/archive/2011/07/09/2101696.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值