简体   繁体   English

最初启动表单时如何隐藏组合框或标签

[英]How to hide a combobox or label when the form is initially launched

样本图片 I have developed a form layout in QT designer. 我已经在QT设计器中开发了表单布局。 I want to hide a label and combo box when the form is shown up initially or when the application launched. 我想在最初显示表单或启动应用程序时隐藏标签和组合框。 That particular combo box should be shown up only when particular option is selected. 仅当选择了特定选项时,才应显示该特定组合框。

I tried doing this: 我尝试这样做:

 if self.comboBox_10.itemText(index) == "Option 1":
        self.label_20.show()
        self.comboBox_11.show()
    elif self.comboBox_10.itemText(index) == "Option 2":
        self.label_20.hide()
        self.comboBox_11.hide()

This hides the label and combobox only when the option is selected for the second time not when the form is initially launched. 仅当第二次选择该选项时才隐藏标签和组合框,而不是在最初启动表单时隐藏。

def __init__(self):
self.comboBox_10.currentIndexChanged.connect(self.selectionchange)
def selectionchange(self, index):
if self.comboBox_10.itemText(index) == "Option1":
        self.label_20.show()
        self.comboBox_11.show()
elif self.comboBox_10.itemText(index) == "Option2":
        self.label_20.hide()
        self.comboBox_11.hide()`

I want to hide Option 2 when the form is launched initially. 我想在最初启动表单时隐藏选项2。

First, You'd better understand Qt's Signal and Slot mechanism. 首先,您最好了解Qt的Signal and Slot机制。 Signal means event in Qt, and Slot means signal handler. Signal表示Qt中的事件,而Slot表示信号处理程序。 You should "connect" a "signal" to your "slot". 您应该将“信号”“连接”到“插槽”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM