我想在不同的選項卡中運行我的應用程序。現在,它在主窗口中運行。我已經完成了一些關於如何創建制表符的搜索工作。我發現這是有用的,但不能滿足我的要求使用TabWidget在選項卡中運行Pyqt UI
Create TAB and create textboxes that take data in the TAB-page
我想有添加新的選項卡(如Chrome的新標籤)的功能 下面是我的代碼示例。我在評論中描述了我需要的東西。
from PyQt4 import Qt, QtCore, QtGui
import sys
class Map(QtGui.QMainWindow):
def __init__(self,parentQExampleScrollArea=None,parentQWidget = None):
super(Map,self).__init__()
self.initUI()
#Initialize the UI
def initUI(self):
#Initilizing Menus toolbars
#This must be maintained in all tabbed panes
filename = ""
#Filename is obtained through open file button in file menu
self.filename = filename
def paintEvent(self, e):
qp = QtGui.QPainter()
qp.begin(self)
self.drawPoints(qp,self.filename)
qp.end()
def drawPoints(self, qp,FILENAME=""):
#Read contents in file
#Get the necessary coordinates
#A separate class for storing the info of all the coordinates
#Run a for loop for all the coordinates in the list
#Actually, object is created here and image of that object is set
# as a square using the coordinates
qp.setBrush(QtGui.QColor(255, 0, 20, 200))
qp.drawRect(20,20,75,75)
qp.drawRect(100,20,75,75)
self.update()
#There are many functions to handle keyboard and mouse events
def main():
#How do I modify so that I can have multiple tabs
#And show images of the coordinates in files
#Basically I want to have the feature of opening many files
# and displaying them in UI
#Basically a feature to add a new tab
#like that of in eclipse netbeans sublime etc
app = QtGui.QApplication(sys.argv)
myQExampleScrollArea = Map()
myQExampleScrollArea.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
在此先感謝.. :)
感謝kitsune(再次..我記得你回答我以前的問題)。是的,我可以實現這一點,但問題是我處理了很多全局變量。每個選項卡都應該重新運行整個程序。是的,我可以將全局變量設爲實例變量,但這會使我的代碼更加混亂。請在此建議。 – phaigeim 2014-09-04 07:35:17
因此,您想要像在Web瀏覽器中那樣自動添加小部件,並且不要在其中創建變量?我不知道我理解你的發言已更正,但請閱讀我上次編輯的答案。 – 2014-09-04 08:13:08
是的,這將是有益的..我會嘗試修改我的代碼,使其工作。 – phaigeim 2014-09-04 09:28:47