2016-09-15 13 views
1

私は、メインウィンドウにタブウィジェットを含むQtデザイナーを使って簡単なGUIアプリケーションを開発しました。タブウィジェットは、異なる機能を持つ3つのページで構成されています(Tab1 = 'Home'、Tab2 = 'Inspection'、Tab3 = 'View Results')。ボタンを使ってQTabWidgetタブを変更する

希望するタブを手動でクリックせずにTab2とTab3にジャンプするには、Tab1のプッシュボタン(Inspection/View Results)を押してください。誰も私にそれをする方法をアドバイスできますか?私はより良い情報のスナップショット画像を添付しています

以下

Home widget snapshot

は私のコードです:

あなたが使用できる
from __future__ import division 
from skimage.measure import compare_ssim as ssim 
#from PyQt4.uic import photo_rc 
import matplotlib.pyplot as plt 
import numpy as np 
import sys 
import cv2 
from PyQt4 import QtCore, QtGui, uic 
from PyQt4.QtGui import * 

gui_file = 'i-MIS Alpha.ui' # Enter GUI file name 


[Ui_MainWindow, QtBaseClass] = uic.loadUiType(gui_file) 
#[Ui_DialogBox, QtBaseClass] = uic.loadUiType(gui_dialog) 


class Inspection(QtGui.QMainWindow, Ui_MainWindow): 

    def __init__(self): 
    QtGui.QMainWindow.__init__(self) 
    Ui_MainWindow.__init__(self) 
    self.setupUi(self) 
    self.capture_button.clicked.connect(self.captureImage) 
    self.inspect_button.clicked.connect(self.displayImage) 
    self.deviceBox.activated.connect(self.selectDeviceCombo) 
    self.startInspectionBtn.clicked.connect(self.enterLotID) 
    self.inspect_button.clicked.connect(self.displayResults) 
    self.viewResultBtn.clicked.connect(self.viewResults) 


def enterLotID(self): 
    title, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter the Lot ID:') 
    if ok: 
     self.accept.setText(str(title)) 



def displayImage(self): # Perform image comparison at 'Display' tab 
    sample_label = 'c:/Users/mohd_faizal4/Desktop/Python/Image/Picture 6.jpg' 
    self.sample_label.setScaledContents(True) 
    self.sample_label.setPixmap(QtGui.QPixmap(sample_label)) 

def selectDeviceCombo(self, event): 
    self.var_Selected = self.deviceBox.currentText() 
    #print ('The user selected value now is:') 
    print ('Device = ' + self.var_Selected) 

    if self.var_Selected.lower() == 'xf35': 
     print("Great! Device Id is - " + self.var_Selected + '!') 
     source_label ='c:/Users/mohd_faizal4/Desktop/Python/Image/Picture 4.jpg' 
     self.source_label.setScaledContents(True) 
     self.source_label.setPixmap(QtGui.QPixmap(source_label)) 
    elif self.var_Selected.lower() == 'xf38': 
     print("Great! Device Id is - " + self.var_Selected + '!') 
     source_label ='c:/Users/mohd_faizal4/Desktop/Python/Image/Picture 5.jpg' 
     self.source_label.setScaledContents(True) 
     self.source_label.setPixmap(QtGui.QPixmap(source_label)) 
    elif self.var_Selected.lower() == 'x38c': 
     print("Great! Device Id is - " + self.var_Selected + '!') 
     source_label ='c:/Users/mohd_faizal4/Desktop/Python/Image/Picture 7.jpg' 
     self.source_label.setScaledContents(True) 
     self.source_label.setPixmap(QtGui.QPixmap(source_label)) 
    else: 
     print ("Pls select device id. It's reguired field!") 


def captureImage(self): # Capture image and display on 'Sample' column under Inspection 

    cam = cv2.VideoCapture(0) 

    i = 0 
    while i < 10: 
     ret, frame = cam.read() 
     cv2.imshow('test', frame) 
     #self.sample_label.setScaledContents(True) 
     #self.sample_label.setPixmap(QtGui.QPixmap(sample_label)) 
     if not ret: 
      break 
     k = cv2.waitKey(2) 

     if k%256 == 27: 
     # ESC pressed 
     print("Escape hit, closing...") 
     break 
     if k % 256 == 32: 
      # SPACE pressed 
      img_name = "XBU 12345.6_{}.jpeg".format(i) 
      cv2.imwrite(img_name, frame) 
      print("{}".format(img_name)) 
      i += 1 

    cam.release() 
    cv2.destroyAllWindows() 


def viewResults(self): 


def displayResults(self): 
    label_vid01 = 'c:/Users/mohd_faizal4/Desktop/Python/Image/Picture 7.jpg' 
    self.label_vid01.setScaledContents(True) 
    self.label_vid01.setPixmap(QtGui.QPixmap(label_vid01)) 

if __name__ == '__main__': 
    app = QtGui.QApplication(sys.argv) 
    Window = Inspection() 
    Window.show() 
    sys.exit() 

答えて

0

setCurrentIndex (self, int index) 

インデックス秒1と2のために第3のタブ

または

setCurrentWidget (self, QWidget widget) 
+0

私はこれを自分のコードに実装できますか?私はまだ鮮明な画像を取得していません。 –

+0

__init__関数のボタンを作成するスロットに接続する必要があります。これらのスロットの中には上記の関数を使用します。 – basslo

+0

ご協力いただきありがとうございます。やってみます。 –

関連する問題