1

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

require 'Qt'
class Auth < Qt::Widget
  entryIndex = $entryIndex 
  slots 'slotFunctionChanged(int)'

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

    entry_ui

    show   
  end

  def entry_ui
    @entryLabel = Qt::Label.new "Entry: ", self 
    @entryLabel.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"

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

  end 

 def slotEntryChanged(entryIndex)
 case entryIndex 
    when 0 
      @acc.show
    when 1 
      @acc.hide 
    when 2 
      @acc.show 
  end 
 end 

现在有一个名为 Submit 的按钮,它连接到插槽 'on_clicked_submit()'。

我希望仅当 entryIndex 项目为自定义或非自定义时才会弹出一个对话框。我尝试了以下代码:

  def on_clicked_submit 
      if $entryIndex == 1 || $entryIndex == 8 
      text = Qt::InputDialog.getText self, "Swipe", "Thank you"
  end 

结尾

但是检查 entryIndex 的 if 语句不能正常工作。欢迎提出建议

4

0 回答 0