我已经厌倦了在python类(python2.7&PyQt4)中寻找处理加载的小部件的方法文件.ui(图形用户界面设计器)
代码
form_class = uic.loadUiType("MyPythonProgram.ui")[0]
class MyWindowClass(QtGui.QMainWindow, form_class):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.btn_buscar.clicked.connect(self.buscar)
def addingResultsToQListView(self):
for item in SomeList:
self.listView.addItem(item) ###It's not correct, but cannot find the right one
def onListItemClicked():
getItem = listView.currentItem().text() ###It's not correct, but cannot find the right one
def buscar(self):
getEditText = self.textEdit.toPlainText()
### Don't know how to do this function. I want to get the edittext to search on some website and retrieve the results into a list. then the list will be added to QlistView (just found C++ methods, not for python)
#Finally
getEditText = '' ###After click on 'btn_buscar', want to clear this field
app = QtGui.QApplication(sys.argv)
MyWindow = MyWindowClass(None)
MyWindow.show()
app.exec_()
它可以帮助您获取一些文档,或者帮助您实现python应用程序的混合(如果可能的话,可以是Android),在我向您展示的过程中分别保留.ui和.py层。你知道吗
这是我的.ui以获取更多信息:
'问题' 如何将python函数与.ui上的元素绑定?我尝试了太多的方法,但没有找到合适的方法。需要知道如何处理QlistView和Qedittext。。。谢谢
我就是这样做的:在UI的构造(加载)和更改其内容之间分离类。你知道吗
诀窍是引用
MyWindowClass
,它是gui的构造函数,因此也是gui本身,作为类中控制gui内容的对象(myGui
)。你知道吗在顶层调用
myGui
,然后调用MyWindowClass
作为对象self.gui
。从那时起,每当您想在GUI中寻址某个对象时,您就将其命名为self.gui.
,并添加QObject。你知道吗我也试着理解你想为
pushBotton
做什么。TextEdit的内容(在PyQt中称为lineEdit
btw)存储在变量self.editText
中,该变量被初始化为None
。之后,从用户内容中清除lineEdit
。你知道吗相关问题 更多 >
编程相关推荐