2017-10-19 5 views
1

QInputDialog에 대한 몇 가지 옵션을 설정하려고합니다. 하지만 getText으로 전화하면 이러한 설정이 적용되지 않습니다.QInputDialog의 옵션 설정 방법

팝업 창이 나타나는 모양을 변경하려면 어떻게해야합니까? getText?

import sys 
from PyQt5 import QtWidgets, QtCore 


class Mywidget(QtWidgets.QWidget): 
    def __init__(self): 
     super(Mywidget, self).__init__() 
     self.setFixedSize(800, 600) 

    def mousePressEvent(self, event): 
     self.opendialog() 

    def opendialog(self): 
     inp = QtWidgets.QInputDialog() 

     ##### SOME SETTINGS 
     inp.setInputMode(QtWidgets.QInputDialog.TextInput) 
     inp.setFixedSize(400, 200) 
     inp.setOption(QtWidgets.QInputDialog.UsePlainTextEditForTextInput) 
     p = inp.palette() 
     p.setColor(inp.backgroundRole(), QtCore.Qt.red) 
     inp.setPalette(p) 
     ##### 

     text, ok = inp.getText(w, 'title', 'description') 
     if ok: 
      print(text) 
     else: 
      print('cancel') 

if __name__ == '__main__': 
    qApp = QtWidgets.QApplication(sys.argv) 
    w = Mywidget() 
    w.show() 
    sys.exit(qApp.exec_()) 

답변

1
get*

방법들은 QInputDialog 클래스의 인스턴스없이 호출 될 수있는 수단을 모두 정적이다. Qt는 이러한 메서드에 대해 내부 대화 상자 인스턴스를 생성하므로 설정이 무시됩니다.

가 작동하도록 예를 얻으려면, 당신은 명시 적으로 대화를 몇 가지 더 많은 옵션을 설정하고 표시해야합니다 :

def opendialog(self): 
    inp = QtWidgets.QInputDialog(self) 

    ##### SOME SETTINGS 
    inp.setInputMode(QtWidgets.QInputDialog.TextInput) 
    inp.setFixedSize(400, 200) 
    inp.setOption(QtWidgets.QInputDialog.UsePlainTextEditForTextInput) 
    p = inp.palette() 
    p.setColor(inp.backgroundRole(), QtCore.Qt.red) 
    inp.setPalette(p) 

    inp.setWindowTitle('title') 
    inp.setLabelText('description') 
    ##### 

    if inp.exec_() == QtWidgets.QDialog.Accepted: 
     print(inp.textValue()) 
    else: 
     print('cancel') 

    inp.deleteLater() 

을 이제 당신이 더 많거나 적은 getText가하는 모든 것을 재 구현된다.

+0

감사합니다. – Jonas