1

我有一个下拉菜单,里面有大约 5-6 个项目。

当我在 ComboBox 中选择特定选项时,我希望其他小部件出现在同一窗口中。例如:当我在 ComboBox 中选择“1-Standard”时,acc_ui必须弹出其中定义的小部件等等。

这是我试过的代码:

require 'Qt'
class Auth < Qt::Widget

  slots 'slotFunctionChanged(int)'

  def initialize(parent=nil)
    super(parent)
    setWindowTitle("Action");
    setFixedSize 750,530

    function_ui

    show   
  end

  def function_ui
    @funLabel = Qt::Label.new "Func: ", self 
    @funLabel.setFont Qt::Font.new("Times New Roman", 14)
    combo = Qt::ComboBox.new self 
    combo.setFont Qt::Font.new("Times New Roman", 12 )
    combo.addItem "1- Standard"
    combo.addItem "2- Custom"
    combo.addItem "3- Non-custom"
    combo.addItem "4- Non-Standard"
    combo.addItem "5- Plastic"

    connect combo, SIGNAL('activated(int)'), self, SLOT('slotFunctionChanged(int)')
    combo.resize 170,20
    combo.move 170,100
    @funLabel.move 95,100

  end 

  def slotFunctionChanged(index)
    case index 
    when 0 
      acc_ui()
    when 1 
      store_ui()     
    end 
  end 

  def acc_ui 
    @accLineedit = Qt::Lineedit.new(self)
    @accLineedit.setFont Qt::Font.new("Times New Roman", 12)
    @accLabel = Qt::Label.new "Acc: ", self 
    @accLabel.setFont Qt::Font.new("Times New Roman", 14)
    @accLabel.move 95,185
    @accLineedit.resize 170,20
    @accLineedit.move 170,185
  end 

  def store_ui
    @storeLineedit = Qt::Lineedit.new(self)
    @storeLineedit.setFont Qt::Font.new("Times New Roman", 12)
    @storeLabel = Qt::Label.new "Store: ", self 
    @storeLabel.setFont Qt::Font.new("Times New Roman", 14)
    @storeLabel.move 120,210
    @storeLineedit.resize 140,20
    @storeLineedit.move 170,210

  end 

end 

app = Qt::Application.new(ARGV)
widget = Auth.new
widget.show
app.exec
4

1 回答 1

0
  • 将所有代码移出 acc_ui和移出store_uifunction_ui
  • in function_ui:将该show方法应用于所有应默认显示的小部件,将该hide方法应用于所有应默认隐藏的小部件
  • in acc_uiand store_ui: 只使用showandhide方法让小部件随心所欲地出现和消失
于 2016-02-13T12:21:22.820 回答