2016-02-12 33 views
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 
+0

問題是什麼?我們需要描述它沒有正確執行的內容。請閱讀「[問]」。另外,這是證明問題所需的最基本的代碼嗎?如果沒有,請減少它。大量的代碼減慢了我們幫助你的能力,並且耗盡了我們幫助他人的時間。 [MCVE]。 –

+0

對不起。這是我第一次發帖,從下次開始就會記住這一點。 我在這裏的問題是:內部case語句,當我嘗試調用一個方法,我已分別定義,它不會被調用。 – topjay

回答

0
  • acc_ui移動的所有代碼,並從store_uifunction_uifunction_ui
  • :應用show方法應該在默認情況下顯示的所有窗口小部件,並將hide方法應用於所有應默認隱藏的小工具
  • in acc_ui and store_ui:only use showhide方法讓小部件出現並隨意消失
+0

如果我想顯示storeLabel小部件,我該如何顯示它? 顯示和隱藏方法似乎不適用於 – topjay

+0

'@ storeLabel.show'應該這樣做。如果沒有,您可能需要將上次的代碼上傳到https://gist.github.com/並分享鏈接。我很樂意在那裏檢查,並幫助您運行。 – bogl

+0

謝謝。上述展示和隱藏的方式對我來說確實有效。但是,在處理個案之前,我沒有弄清楚如何設置默認外觀。 – topjay

相關問題