Python之PyQT4的使用技巧集锦
2015-06-14 12:37
886 查看
窗口大小设置
背景图片设置
布局问题
UnboundLocalError
http://www.cnblogs.com/dcb3688/p/4311138.html
你会发现它讲的并没有什么卵用,你需要的是设置布局,就是你点击右键会有布局在那里,你可以进行水平布局或者垂直布局。
http://www.bubuko.com/infodetail-589789.html
把这几句代码加上去就可以了。
布局出现了以上问题,根据Stack Overflow的回答就是布局重复了。
http://stackoverflow.com/questions/7684975/pyqt4-qt-designer-making-dynamic-guis
然后我做了以下改变。
最后效果就是:
http://blog.csdn.net/joeblackzqq/article/details/35278665
背景图片设置
布局问题
UnboundLocalError
窗口大小设置
参考下面这篇博客:http://www.cnblogs.com/dcb3688/p/4311138.html
你会发现它讲的并没有什么卵用,你需要的是设置布局,就是你点击右键会有布局在那里,你可以进行水平布局或者垂直布局。
背景图片设置
参考这篇博客,好像有点用。http://www.bubuko.com/infodetail-589789.html
[code]palette1.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap(‘../../../Document/images/17_big.jpg‘))) # 设置背景图片 self.setPalette(palette1) self.setAutoFillBackground(True) # 不设置也可以
把这几句代码加上去就可以了。
布局问题
QLayout: Attempting to add QLayout “” to QWidget “t2”, which already has a layout布局出现了以上问题,根据Stack Overflow的回答就是布局重复了。
http://stackoverflow.com/questions/7684975/pyqt4-qt-designer-making-dynamic-guis
然后我做了以下改变。
[code]# -*- coding: utf-8 -*- import sys import os import re import time from PyQt4 import QtCore, QtGui from ui_nao2 import Ui_Form from file_nao import file_name # def update_textBrowser(self): # self.textBrowser.append(self.ActionBox.currentText()) ''' class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QStackedWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) def event_click(self,parent=None): # self.ui.ConfirmBtn.setCheckable(True) if slef.ui.ConfirmBtn.isChecked(): self.ui.textBrowser.append(self.ui.ActionBox.currentText()) ''' def Main(): file_num,list_filename,list_filefullname = file_name() app = QtGui.QApplication(sys.argv) Form = QtGui.QWidget() myapp = Ui_Form() myapp.setupUi(Form) i = 0 for i in range(file_num): # myapp.Form.ActionBox.addItem(list_filename[i]) # myapp.ActionBox.addItem(list_filename[i]) #myapp.ui.ActionBox.addItem(list_filename[i]) #myapp.ui.AudioBox.addItem(list_filename[i]) i = i + 1 # print i if i == file_num: # myapp.ui.textBrowser.append(u'目前选择的方案为\n') #追加内容 Form.show()#myapp.show() ''' while True: time.sleep(1) if myapp.ui.ConfirmBtn.isChecked(): myapp.ui.textBrowser.append(myapp.ui.ActionBox.currentText()) ''' # print myapp.ui.ActionBox.currentText() # while 1: # if myapp.ui.ConfirmBtn.event == True: # print myapp.ui.ActionBox.currentText() # myapp.ui.textBrowser.append(u'test1\n') # myapp.ui.textBrowser.append(myapp.ui.ActionBox.currentText()) # myapp.show() # if myapp.ui.ConfirmBtn.event == True: sys.exit(app.exec_()) # Python不仅仅要在那一行和自身对齐,还需要和后面的程序对其 if __name__ == "__main__": # __main__是用来做当这个模块被调用之后就会不执行这个程序了 Main() # 使用该函数之后关闭界面不会再出现意外 ''' 在uipy里面需要增加的东西 def Dance_Update_TextBrowser(self): self.textBrowser.append(self.ActionBox.currentText()) def Action_Update_TextBrowser(self): self.textBrowser.append(self.AudioBox.currentText()) QtCore.QObject.connect(self.ConfirmDanceBtn, QtCore.SIGNAL(_fromUtf8("clicked()")), self.Dance_Update_TextBrowser) QtCore.QObject.connect(self.ConfirmActionBtn, QtCore.SIGNAL(_fromUtf8("clicked()")), self.Action_Update_TextBrowser) '''
最后效果就是:
UnboundLocalError
参考这篇博客:http://blog.csdn.net/joeblackzqq/article/details/35278665
相关文章推荐
- Simulate Blackjack Game - Card Generator
- Simulate Blackjack Game - Card Generator
- 搭建VTK+ITK+Python系统
- Python遍历文件夹,删除空文件夹,过滤特定大小和格式的文件
- 人人都懂的编程课(Python)
- 人人都懂的编程课(Python)
- Python 各种IDE比较
- python RSA签名
- leetcode Excel Sheet Column Number python
- leetcode Excel Sheet Column Title python
- leetcode Largest Number python
- leetcode Majority Element python
- leetcode Word Break python
- python opencv face detection
- Python绘图详解
- Python中使用中文
- Python爬取新闻网标题、日期、点击量
- python操作EXCEL文档
- Python实现打印二叉树某一层的所有节点
- python3.4连接mysql