2011-08-11 5 views
2

pyqt4 콤보 상자의 드롭 다운에 대한 콜백 또는 이벤트가 있습니까? 그냥 self.connect(self.ui.combobox,SIGNAL("activated(int)"),self.refresh 어쩌면pyqt4의 콤보 상자의 드롭 다운 이벤트/콜백

+0

당신은 드롭 다운 메뉴가 표시 될 때 방출되는 신호를 의미입니까? 즉, 사용자가 콤보 박스를 클릭하면? –

+0

예, 사용자가 콤보 박스를 클릭합니다. – unice

답변

2

QCombobox는 QAbstractItemView (기본적으로 QListView)를 사용하여 드롭 다운 항목 (view() 속성을 통해 액세스 가능)을 표시합니다. 그 목적을위한 어떤 신호도 알지 못합니다.

하지만 당신은 콤보 상자의보기에 installEventFilter를 사용하여 트릭을 할 것 eventFilter을 설정하고 eventFilter 방법을 구현할 수 있습니다

from PyQt4 import QtCore, QtGui 
class ShowEventFilter(QtCore.QObject): 
    def eventFilter(self, filteredObj, event): 
     if event.type() == QtCore.QEvent.Show: 
      print "Popup Showed !" 
      # do whatever you want 
     return QtCore.QObject.eventFilter(self, filteredObj, event) 

if __name__ == '__main__': 
    app = QtGui.QApplication([]) 
    cb = QtGui.QComboBox() 
    cb.addItems(['a', 'b', 'c']) 

    eventFilter = ShowEventFilter() 
    cb.view().installEventFilter(eventFilter) 
    cb.show() 
    app.exec_() 
0

처럼 당신은 (는 QWidget에서 상속)

customContextMenuRequested(const QPoint &pos) 

신호를 시도 할 수 있을까?

+0

어쩌면 대답이 아닙니다. – user1767754

관련 문제