2016-11-17 1 views
0

그래서이 GUI를 개발했지만 사용자 입력에 따라 QcomboBox를 여러 개의 다른 슬롯에 연결하는 데 문제가 있습니다. 필자는 사용자가 QcomboBox에서 드라이브를 선택하고 QpushButton을 누른 다음 자동으로 네트워크 드라이브로 연결되도록하고 싶습니다. QcomboBox 멀티 슬롯 연결의 PYQT QpushButton

screenshot

는 지금 일 동안 논리를 통해 내 머리를 긁적있다. 코드의 두 번째 부분은 다음과 같이해야합니다 (아마도?) :

def retranslateUi(Self, MainWindow): 
    self.btnGo.clicked.connect(self.DriverSelectClicked) 

def DriverSelectClicked(self): 
    if self.comboBox1.currentIndex() == 0: 
     os.startfile('C:/') 
    if self.comboBox1.currentIndex() == 1: 
     os.startfile('Z:/')  
+0

클릭 신호에서 currentIndexChanged로 변경해야합니다. – Achayan

답변

1

콤보 상자에서 직접 드라이브 경로 정보를 가져와야합니다. 콤보 상자 항목의 텍스트를 설정하는 것 외에, 당신은 또한 당신이 클릭을 처리 할 때 그리고 나중에, 당신은 그냥 드라이브 및 사용에 직접

이 들어있는 데이터 필드를 읽을 수있는 데이터
drives = ['C:\\', 'Z:\\'] 
for drive in drives: 
    text = '[{}] Disk Drive'.format(drive) 
    self.comboBox1.addItem(text, drive) 

을 설정할 수 있습니다
def DriverSelectClicked(self): 
    drive = self.comboBox1.itemData(self.comboBox1.currentIndex()) 
    if drive: 
     os.startfile(drive) 
+0

감사합니다. @ Brendan Abel! 이것은 완벽하게 작동했습니다. –