Home > Backend Development > Python Tutorial > Python PyQt4 implements QQ drawer effect

Python PyQt4 implements QQ drawer effect

不言
Release: 2018-04-20 13:43:13
Original
2180 people have browsed it

This article mainly introduces Python PyQt4 to implement QQ drawer effect in detail. It has certain reference value. Interested friends can refer to it.

The example of this article shares with everyone the implementation of QQ in Python PyQt4. The specific code for displaying the drawer effect is for your reference. The specific content is as follows

First look at the screenshot effect:

Mainly uses QT’s QTabWidget and QToolBox Page widget

# -*- 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_()
Copy after login

Problem record

1. When using Chinese in the script, an error message appears:

SyntaxError: 'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte

Need to save the *.py file as utf-8, I use gvim, and I have never understood the encoding settings of vim, so I used a relatively stupid method, opening it with Notepad and saving it as utf-8 format

2. At the beginning , I placed the avatar directory image in the \Python32\Lib\site-packages directory, and then called the module in the explanation, but it could not be displayed. Later, I changed to the absolute path


The above is the detailed content of Python PyQt4 implements QQ drawer effect. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template