本文实例为大家分享了PythonPyQt4实现QQ抽屉效果展示的具体代码,供大家参考,具体内容如
本文实例为大家分享了Python PyQt4实现QQ抽屉效果展示的具体代码,供大家参考,具体内容如下
先看截图效果:
主要是使用了QT的QTabWidget、QToolBox多页窗口部件
# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
class MyQQ(QTabWidget):
def __init__(self,parent=None):
super(MyQQ,self).__init__(parent)
toolButton1=QToolButton()
toolButton1.setText(self.tr("gavin"))
toolButton1.setIcon(QIcon("d:/image/1.png"))
toolButton1.setIconSize(QSize(60,60))
toolButton1.setAutoRaise(True)
toolButton1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
toolButton2=QToolButton()
toolButton2.setText(self.tr("问题的方法"))
toolButton2.setIcon(QIcon("d:/image/2.png"))
toolButton2.setIconSize(QSize(60,60))
toolButton2.setAutoRaise(True)
toolButton2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
toolButton3=QToolButton()
toolButton3.setText(self.tr("为什么"))
toolButton3.setIcon(QIcon("d:/image/3.png"))
toolButton3.setIconSize(QSize(60,60))
toolButton3.setAutoRaise(True)
toolButton3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
groupbox1=QGroupBox()
vlayout1=QVBoxLayout(groupbox1)
vlayout1.setMargin(10)
vlayout1.setAlignment(Qt.AlignCenter)
vlayout1.addWidget(toolButton1)
vlayout1.addWidget(toolButton2)
vlayout1.addStretch()
groupbox2=QGroupBox()
vlayout2=QVBoxLayout(groupbox2)
vlayout2.setMargin(10)
vlayout2.setAlignment(Qt.AlignCenter)
vlayout2.addWidget(toolButton3)
vlayout2.addStretch()
groupbox3=QGroupBox()
toolbox1 = QToolBox()
toolbox1.addItem(groupbox1,self.tr("我的好友"))
toolbox1.addItem(groupbox2,self.tr("同事"))
toolbox1.addItem(groupbox3,self.tr("黑名单"))
toolbox2 = QToolBox()
self.addTab(toolbox1, "联系人")
self.addTab(toolbox2, "群/讨论组")
app=QApplication(sys.argv)
myqq=MyQQ()
myqq.setWindowTitle("QQ2012")
myqq.show()
app.exec_()
问题记录
1.脚本中使用中文处,提示错误:
SyntaxError:<unicode error> 'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
需要将*.py文件保存成utf-8, 我用的是gvim,一直没搞明白vim的编码设置,所以我用了种比较笨的方法,用记事本打开,另存为utf-8格式
2.一开始,我把头像目录image放在\Python32\Lib\site-packages目录下,然后在解释中调用模块,但是不能显示,后来就改用了绝对路径
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
Python PyQt4 抽屉