Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Why does my tearoff menu have a title bar?
Forum Updated to NodeBB v4.3 + New Features

Why does my tearoff menu have a title bar?

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 579 Views 2 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.
  • Terrence MitchemT Offline
    Terrence MitchemT Offline
    Terrence Mitchem
    wrote on last edited by
    #1

    I'm displaying a tearoff menu when a specific button is right-clicked. For some reason, the menu is displaying with a title bar, complete with a close button.

    menu.png

    Is this the default behavior? If so, can it be changed?

    Code that creates the menu:

    SettingsButtonContextMenu = QMenu(btn)
    
    SettingsButtonContextMenu.addAction("&Settings", settings_action)
    SettingsButtonContextMenu.addAction("S&ave", save_action)
    SettingsButtonContextMenu.addAction("E&xit", exit_action)
    

    Event handler that display the menu:

    def mouse_press_handler(button, mb, e):
        print(button.objectName())
        if mb == Qt.MouseButton.RightButton:
            SettingsButtonContextMenu.showTearOffMenu()
    
    JoeCFDJ 1 Reply Last reply
    0
    • Terrence MitchemT Terrence Mitchem

      I'm displaying a tearoff menu when a specific button is right-clicked. For some reason, the menu is displaying with a title bar, complete with a close button.

      menu.png

      Is this the default behavior? If so, can it be changed?

      Code that creates the menu:

      SettingsButtonContextMenu = QMenu(btn)
      
      SettingsButtonContextMenu.addAction("&Settings", settings_action)
      SettingsButtonContextMenu.addAction("S&ave", save_action)
      SettingsButtonContextMenu.addAction("E&xit", exit_action)
      

      Event handler that display the menu:

      def mouse_press_handler(button, mb, e):
          print(button.objectName())
          if mb == Qt.MouseButton.RightButton:
              SettingsButtonContextMenu.showTearOffMenu()
      
      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @Terrence-Mitchem said in Why does my tearoff menu have a title bar?:

      QMenu

      Try
      SettingsButtonContextMenu->setWindowFlags( (Qt::WindowFlags)Qt::FramelessWindowHint );

      Terrence MitchemT 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        @Terrence-Mitchem said in Why does my tearoff menu have a title bar?:

        QMenu

        Try
        SettingsButtonContextMenu->setWindowFlags( (Qt::WindowFlags)Qt::FramelessWindowHint );

        Terrence MitchemT Offline
        Terrence MitchemT Offline
        Terrence Mitchem
        wrote on last edited by Terrence Mitchem
        #3

        @JoeCFD said in Why does my tearoff menu have a title bar?:

        @Terrence-Mitchem said in Why does my tearoff menu have a title bar?:

        QMenu

        Try
        SettingsButtonContextMenu->setWindowFlags( (Qt::WindowFlags)Qt::FramelessWindowHint );

        So here's the proposed new code:

        SettingsButtonContextMenu = QMenu(btn)
        SettingsButtonContextMenu.setWindowFlags(Qt.WindowType.FramelessWindowHint)
        
        SettingsButtonContextMenu.addAction("&Settings", settings_action)
        SettingsButtonContextMenu.addAction("S&ave", save_action)
        SettingsButtonContextMenu.addAction("E&xit", exit_action)
        

        This results in the menu being displayed as soon as the main window is:

        menu.png

        No idea what's up with that.

        JoeCFDJ 1 Reply Last reply
        0
        • Terrence MitchemT Terrence Mitchem

          @JoeCFD said in Why does my tearoff menu have a title bar?:

          @Terrence-Mitchem said in Why does my tearoff menu have a title bar?:

          QMenu

          Try
          SettingsButtonContextMenu->setWindowFlags( (Qt::WindowFlags)Qt::FramelessWindowHint );

          So here's the proposed new code:

          SettingsButtonContextMenu = QMenu(btn)
          SettingsButtonContextMenu.setWindowFlags(Qt.WindowType.FramelessWindowHint)
          
          SettingsButtonContextMenu.addAction("&Settings", settings_action)
          SettingsButtonContextMenu.addAction("S&ave", save_action)
          SettingsButtonContextMenu.addAction("E&xit", exit_action)
          

          This results in the menu being displayed as soon as the main window is:

          menu.png

          No idea what's up with that.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @Terrence-Mitchem
          Try the following and use stylesheet to set color for text and background

                # Get the position of the button
                  button_pos = self.button.mapToGlobal(self.button.pos())
          
                  # Adjust the position as needed
                  menu_position = button_pos + self.button.rect().bottomLeft()
          
                 SettingsButtonContextMenu.showTearOffMenu( menu_position )
          
          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            Like the documentation says showTearOffMenu() places the menu inside its own widget. It has a title bar so it is permanent and can be moved around. Use popup() instead. This is the right function for context menus.

            Terrence MitchemT 1 Reply Last reply
            4
            • S SimonSchroeder

              Like the documentation says showTearOffMenu() places the menu inside its own widget. It has a title bar so it is permanent and can be moved around. Use popup() instead. This is the right function for context menus.

              Terrence MitchemT Offline
              Terrence MitchemT Offline
              Terrence Mitchem
              wrote on last edited by
              #6

              @SimonSchroeder

              Thank you! This was the solution.

              1 Reply Last reply
              0
              • Terrence MitchemT Terrence Mitchem has marked this topic as solved on

              • Login

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