首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >小部件应根据下拉菜单中选择的选项显示或隐藏。

小部件应根据下拉菜单中选择的选项显示或隐藏。
EN

Stack Overflow用户
提问于 2016-02-12 20:12:59
回答 1查看 317关注 0票数 1

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

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

这是我尝试过的代码:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-13 12:21:22

  • 将所有代码从acc_uistore_ui移动到function_ui
  • function_ui中:将show方法应用于默认显示的所有小部件,将hide方法应用于默认应隐藏的所有小部件
  • acc_uistore_ui中:只使用showhide方法让小部件按您的意愿出现和消失
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35371419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档