Drop down menu in @toolbar

Hello,

I am trying to create a menu in the toolbar in the style of the Ruler or the Technology selector.
A action trig and a drop down menu together. I manage to do the two separately but not together.
I have no idea how to bin the action with the menu. Anybody did this before ?

Alex

Comments

  • Hi, Alex!

    I think you need to call QToolButton::setDefaultAction.

  • Hi sir,
    Can you get us more detail sample code for that ?
    I want to create a menu buttom in Klayout to call my Ruby/DRC code.
    But , I don't know how to call QToolButtom.. in my code...
    Thanks.

  • @jiunnweiyeh KLayout employs a menu abstraction instead of direct Qt element access. The reason is that I cannot ensure compatibility of the Widget hierarchy across multiple releases.

    The involved classes here are AbstractMenu and Action:

    Here is an example:

    mw = RBA::MainWindow::instance
    
    # create a toolbar submenu
    mw.menu.insert_menu("@toolbar.end", "toolbar_submenu", "Submenu")
    
    # fill the menu with three items
    (1..3).each do |item|
    
      item_name = "item#{item}"
    
      # create an Action object to bind the item to
      action = RBA::Action::new
      action.title = "Item #{item}"
      action.on_triggered do
        # implement the action here ...
        RBA::MessageBox::info("Info", "Item #{item} clicked!", RBA::MessageBox::Ok)
      end
    
      # Insert the action as an item into the menu
      mw.menu.insert_item("@toolbar.toolbar_submenu.end", item_name, action)
    
    end
    

    Matthias

  • Hello Matthias,

    Ruby is cool ! But I am still far away from building it as a master. I start to do something by using above submenu code,
    and wonder if I can get the submenu just launching Klayout, without running the code again ?

    Maybe there is some magic skill here ?

    Thanks
    Vincent

  • HI Vincent Lin,

    you can enabling "run on startup" from the setup.

  • Hello RawrRanger,

    Thanks for your help, I learned lots of coding skill from your awesome sharing on other topics 😁

    Good day,

    Vincent
Sign In or Register to comment.