Drop down menu in @toolbar


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 ?



  • 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...

  • @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)
      # Insert the action as an item into the menu
      mw.menu.insert_item("@toolbar.toolbar_submenu.end", item_name, action)


Sign In or Register to comment.