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. Adding item to toolbar context menu
Qt 6.11 is out! See what's new in the release blog

Adding item to toolbar context menu

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 10.3k 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.
  • T Offline
    T Offline
    TheClassic
    wrote on last edited by
    #1

    Is there a way to add an item to the context menu that is used for showing/hiding QDockWidgets and QToolbars. I have a widget that I don't think makes sense as either of these that I would like to hide/show using this menu.

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wagner.reck
      wrote on last edited by
      #2

      Added an Action to your context menu connected to a slot of your QMainWindow where you can call void removeDockWidget ( QDockWidget * dockwidget ) or void removeToolBar ( QToolBar * toolbar )

      'I will not buy this record, it's scratch'

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TheClassic
        wrote on last edited by
        #3

        The widget is neither a dockwidget nor a toolbar.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wagner.reck
          wrote on last edited by
          #4

          where the widget is inserted? inside of a QLayout? (QLayout has a removeWidget(QWidget*) )

          did you tried QWidget::setVisible ( bool visible ) method?

          'I will not buy this record, it's scratch'

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TheClassic
            wrote on last edited by
            #5

            What I don't know how to do is add something to the applications built in context menu

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sigrid
              wrote on last edited by
              #6

              You can reimplement "QMainWindow::createPopupMenu()":http://doc.qt.nokia.com/latest/qmainwindow.html#createPopupMenu and return your own menu. Alternatively, you can add to the existing context menu and return that one. For example:

              @

              #include <QtGui>

              class MainWindow : public QMainWindow
              {
              Q_OBJECT
              public:
              MainWindow()
              {
              QDockWidget *dock1 = new QDockWidget(this);
              dock1->setWindowTitle("Dock 1");
              dock1->setWidget(new QTextEdit(dock1));
              QToolBar *tool = new QToolBar(this);
              tool->setWindowTitle("Tool");
              tool->addAction("Test action");

              addDockWidget(Qt::TopDockWidgetArea, dock1);
              addToolBar(tool);

              setCentralWidget(new QTextEdit(this));
              };

              QMenu* createPopupMenu ()
              {
              QMenu *menu = QMainWindow::createPopupMenu();
              menu->addAction("An added action");
              return menu;
              }

              };

              #include "main.moc"

              int main(int argc, char** argv)
              {
              QApplication app(argc, argv);
              MainWindow window;
              window.show();
              return app.exec();

              }

              Does this give you what you need?
              @

              1 Reply Last reply
              1
              • T Offline
                T Offline
                TheClassic
                wrote on last edited by
                #7

                Thanks sigrid, that looks like what I'm looking for.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rickramky
                  wrote on last edited by
                  #8

                  Is it possible to add items to the taskbar context menu? I am referring
                  to the menu produced when right clicking on the time within Windows XP
                  (ie "Toolbars" to Properties").

                  I want to add items onto this menu, but have not found a guide on how to
                  do this yet (I expect there is a registry entry required to do this). I
                  would either like to add items to this menu or edit the existing items
                  on the menu.

                  Does anyone know how to do this?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sigrid
                    wrote on last edited by
                    #9

                    It is not possible to add items to the taskbar context menu using Qt.

                    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