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. Context Menus
Forum Updated to NodeBB v4.3 + New Features

Context Menus

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.0k 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.
  • M Offline
    M Offline
    mchris357
    wrote on last edited by
    #1

    I currently have a tab bar that is the central widget for my main window. The user can create several tabs by inputting appropriate information, and each tab is a widget of it's own. If I wanted to implement a context menu for each individual tab, would I need to create a new class for that tab subclassed from QTabWidget?

    I'm asking this because my Tab widget is currently declared in my main window class, and it seems it would be more complicated to use the main window context menu event handler class to determine which tab triggered the context menu. I get the impression that in order to have a context menu for a widget, I must either pass the event on to the parent or implement a context menu event handler for the widget (which would mean I'd have to subclass the tab widget).

    Is this correct?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      You can set the "Context menu policy":http://doc.trolltech.com/latest/qwidget.html#contextMenuPolicy-prop on a widget. If you set it to customContextMenu, the signal customContextMenuRequested() is emitted. You could then connect to that signal, and use the sender() information to determine which page triggered the context menu.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mchris357
        wrote on last edited by
        #3

        @
        void VCMainWindow::CreateNewDataTab( )

        { /BEGIN FUNCTION CREATENEWDATATAB()/

        VCWIDGETPTR NewDataTab       = NULL;
        
        NewDataTab = new VCWIDGET;           //Creates an instance of a new data tab
        
        NewDataTab->setContextMenuPolicy( Qt::CustomContextMenu );
        
        connect( NewDataTab, SIGNAL( customContextMenuRequested( ) ), this, SLOT( ShowTabContextMenu(  ) ) );
        
        VCTabBar->addTab( new VCMPDataTabLayout( this ), "New Tab");
        

        } /CLOSE FUNCTION CREATENEWDATATAB()/@

        I tried that here...it keeps telling me:

        Object::connect: No such signal QWidget::customContextMenuRequested( ) in ..\VCCalculator\source_files\vcwindows.cpp:202

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          If you look at the docs, the signal has this signature:

          @
          void customContextMenuRequested ( const QPoint & pos );
          @

          if you use the correct signatrure, it would work:

          @
          void VCMainWindow::CreateNewDataTab( )

          { /BEGIN FUNCTION CREATENEWDATATAB()/

          VCWIDGETPTR NewDataTab       = NULL;
          
          NewDataTab = new VCWIDGET;           //Creates an instance of a new data tab
          
          NewDataTab->setContextMenuPolicy( Qt::CustomContextMenu );
          
          connect( NewDataTab, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( ShowTabContextMenu(  ) ) );
          
          VCTabBar->addTab( new VCMPDataTabLayout( this ), "New Tab");
          

          } /CLOSE FUNCTION CREATENEWDATATAB()/
          @

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0

          • Login

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