-
- 視窗大小設定
- 背景圖檔設定
- 布局問題
- UnboundLocalError
視窗大小設定
參考下面這篇部落格:
http://www.cnblogs.com/dcb3688/p/4311138.html
你會發現它講的并沒有什麼卵用,你需要的是設定布局,就是你點選右鍵會有布局在那裡,你可以進行水準布局或者垂直布局。
背景圖檔設定
參考這篇部落格,好像有點用。
http://www.bubuko.com/infodetail-589789.html
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
然後我做了以下改變。
# -*- 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)
'''
最後效果就是:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsISMxUDMyYzMyEDNxYDM1EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
UnboundLocalError
參考這篇部落格:
http://blog.csdn.net/joeblackzqq/article/details/35278665