国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

PyQt實(shí)現(xiàn)界面翻轉(zhuǎn)切換效果

2020-02-22 23:45:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

PyQt實(shí)現(xiàn)界面翻轉(zhuǎn)切換效果是用qt的場(chǎng)景功能來(lái)實(shí)現(xiàn)的,用到了QGraphicsView,QGraphicsLinearLayout,QGraphicsWidget等有關(guān)qt場(chǎng)景的庫(kù)。算是對(duì)qt場(chǎng)景的一個(gè)小小的嘗試,涉及內(nèi)容不深,程序效果并是隨心所欲,需要去進(jìn)一步的改善和提高。暫且先把代碼貼在此處,供大家學(xué)習(xí)和指正。

工程包括四個(gè)類(lèi):

界面A,TestMainWindow,用來(lái)充當(dāng)翻轉(zhuǎn)效果的A面。
界面B,TestMainWindowTwo,用來(lái)充當(dāng)翻轉(zhuǎn)效果的B面。
繪圖界面:TestGraphicWidget,用來(lái)繪制界面A和B。
主界面:MainWindow,是一個(gè)全屏的透明窗口,是整個(gè)效果展現(xiàn)的總舞臺(tái),內(nèi)部包含一個(gè)QGraphicsScene和一個(gè)QGraphicsView,用來(lái)展示效果中的界面翻轉(zhuǎn)和界面替換。

整個(gè)效果的原理總結(jié)為幾點(diǎn):

首先,將整個(gè)效果需要的所有界面添加到TestGraphicWidget中,在將TestGraphicWidget放入到QGraphicsScene中,然后經(jīng)QGraphicsScene添加到主界面中。
然后,界面切換實(shí)現(xiàn),兩個(gè)函數(shù),非常簡(jiǎn)單,要顯示A,就把B移除并隱藏,要顯示B,則把A移除并隱藏。

def setOne(self):   self.twoWidget.hide()   self.oneWidget.show()   self.layout.removeItem(self.twoTestWidget)   self.layout.addItem(self.oneTestWidget)   self.view.update()    def setTwo(self):   self.oneWidget.hide()   self.twoWidget.show()   self.layout.removeItem(self.oneTestWidget)   self.layout.addItem(self.twoTestWidget)   self.view.update() 

然后是最重要的,翻轉(zhuǎn)效果的實(shí)現(xiàn),用的是TestGraphicWidget特有的翻轉(zhuǎn)方法,參數(shù)可以根據(jù)實(shí)景情況調(diào)整。

def transeformR(self,count):   r = self.form.boundingRect()   for i in range(1,count):     self.form.setTransform(QTransform()                 .translate(r.width() / 2, r.height() / 2)                 .rotate(91.00/count*i - 360 * 1, Qt.YAxis)                 .translate(-r.width() / 2, -r.height() / 2))     self.waitMethod()     self.view.update()      self.form.setTransform(QTransform()                 .translate(r.width() / 2, r.height() / 2)                 .rotate(270 - 360 * 1, Qt.YAxis)                 .translate(-r.width() / 2, -r.height() / 2))   self.view.update()   if self.formflag %2 == 0:     self.setOne()   else:     self.setTwo()      for i in range(1,count):     self.form.setTransform(QTransform()                   .translate(r.width() / 2, r.height() / 2)                   .rotate(270 + 93.00/count*i - 360 * 1, Qt.YAxis)                   .translate(-r.width() / 2, -r.height() / 2))     self.waitMethod()     self.view.update() 

而且提供了兩種讓程序等待但界面不會(huì)卡死的方法:

def sleep(self,msec):        dieTime = QTime.currentTime().addMSecs(msec)      print dieTime,QTime.currentTime()   #a = 0   while( QTime.currentTime() < dieTime ):     #print "000000000000"     QCoreApplication.processEvents(QEventLoop.AllEvents, 100)         def waitMethod(self):   tt = QElapsedTimer()   tt.start()      q = QEventLoop()   t = QTimer()   t.setSingleShot(True)   self.connect(t, SIGNAL("timeout()"), q.quit)   t.start(1)  # 5s timeout   q.exec_()   if(t.isActive()):     t.stop()   else:     pass      print tt.elapsed()             
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 姜堰市| 四川省| 泗洪县| 崇仁县| 无为县| 集安市| 砀山县| 漳浦县| 大姚县| 武隆县| 黄梅县| 栾川县| 云安县| 凤山县| 澄江县| 西贡区| 喜德县| 登封市| 扎赉特旗| 嘉义县| 枞阳县| 乳山市| 南京市| 扶绥县| 芷江| 阜平县| 新田县| 神农架林区| 陆川县| 徐汇区| 长丰县| 古蔺县| 桑植县| 普兰县| 东源县| 塘沽区| 扶绥县| 汕尾市| 武定县| 共和县| 南皮县|