Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Questions about QToolbar/QToolButton
Forum Updated to NodeBB v4.3 + New Features

Questions about QToolbar/QToolButton

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 469 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    django.Reinhard
    wrote on 3 Jan 2023, 07:39 last edited by
    #1

    Hi,

    I am experimenting a bit with QToolbar and QToolButtons.
    Accidentally I noticed that the toolbar has a context menu that can be used to close the toolbar.

    tb02.png

    • How can I avoid that the toolbar can be closed?

    It should be floatable and moveable, but not closeable.

    Another issue I discovered with the QToolButtons. When I apply setDefaultAction() to existing toolbutton, a down arrow appears, which means that the defaultAction has not been replaced but added.

    tb03.png

    • How can I replace the action of a QToolButton?
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 3 Jan 2023, 08:25 last edited by Bonnie 1 Mar 2023, 08:26
      #2

      About the first question, according to the doc of QMainWindow:

      The createPopupMenu() function creates popup menus when the main window receives context menu events. The default implementation generates a menu with the checkable actions from the dock widgets and toolbars. You can reimplement createPopupMenu() for a custom menu.

      That's the menu you see, not from QToolbar, but from QMainWindow.
      If you didn't need any context menu for the main window, you can simply call setContextMenuPolicy(Qt::NoContextMenu) to disable it (this will not affect the context menu of its child widgets).

      1 Reply Last reply
      2
      • D Offline
        D Offline
        django.Reinhard
        wrote on 3 Jan 2023, 12:42 last edited by
        #3

        Hi,

        @Bonnie said in Questions about QToolbar/QToolButton:

        That's the menu you see, not from QToolbar, but from QMainWindow.

        Ok, as it appears on floating toolbars too, I thought it was the menue of QToolbar.

        @Bonnie said in Questions about QToolbar/QToolButton:

        you can simply call setContextMenuPolicy(Qt::NoContextMenu)

        Thank you very much!!!
        That did the trick :)

        Regarding the second question - I tried lot of different ways - the only way to get desired visible behaviour is toolbar.clear() followed by recreating the entire toolbar from scratch.
        I consider that way as absolutely stupid.
        Especially if I want to replace just the third toolbutton.

        Isn't there a somewhat more clever way to get same result?
        Just as if I want to create a toolbar that reflects function keys.
        There are always 12 function keys and the keys have always the same order. So how can I reflect, that i.e. F8 has changed behaviour?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          django.Reinhard
          wrote on 6 Jan 2023, 12:07 last edited by
          #4

          Hi,

          I worked it out :)

          I replaced QToolBar and subclassed QToolButton and now I have a toolbar, where you can reference a button by position and replace the action without changing attached shortcut.

          That works together with my variant of a statemachine.

          See github StateMachine with branch dynamic_toolbar

          1 Reply Last reply
          0

          1/4

          3 Jan 2023, 07:39

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved