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. QMenu in dialog like the one in Mainwindow
Forum Updated to NodeBB v4.3 + New Features

QMenu in dialog like the one in Mainwindow

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 1.6k Views
  • 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.
  • B Offline
    B Offline
    Bruschetta
    wrote on last edited by
    #1

    Menu in dialog like the one in Mainwindow

    Hello, i'm trying to implement a Mainwindow like menu in one of my Dialogs.
    Till now i have produced this code

    QAction *menuAction;
    QMenuBar *menuBar = new QMenuBar(this);
    QMenu *menu = menuBar->addMenu("Utility");
    menuAction = menu->addAction("PDF");
    connect(menuAction, SIGNAL(triggered()), this , SLOT(pdf_triggered()));
    menuAction = menu->addAction("Print");
    connect(menuAction, SIGNAL(triggered()), this , SLOT(print_triggered()));
    

    This is the result:
    alt text

    As you can see i have been able to insert "PDF" and "Print" options under "Utility" but i would like to create a clickable image+label like i have created in the mainWindow.

    Something like this:
    alt text

    Is it possible? Can someone tell me what functions i have to use or point me to an example?
    Thanks for the answers and time

    jsulmJ 1 Reply Last reply
    0
    • B Bruschetta

      Menu in dialog like the one in Mainwindow

      Hello, i'm trying to implement a Mainwindow like menu in one of my Dialogs.
      Till now i have produced this code

      QAction *menuAction;
      QMenuBar *menuBar = new QMenuBar(this);
      QMenu *menu = menuBar->addMenu("Utility");
      menuAction = menu->addAction("PDF");
      connect(menuAction, SIGNAL(triggered()), this , SLOT(pdf_triggered()));
      menuAction = menu->addAction("Print");
      connect(menuAction, SIGNAL(triggered()), this , SLOT(print_triggered()));
      

      This is the result:
      alt text

      As you can see i have been able to insert "PDF" and "Print" options under "Utility" but i would like to create a clickable image+label like i have created in the mainWindow.

      Something like this:
      alt text

      Is it possible? Can someone tell me what functions i have to use or point me to an example?
      Thanks for the answers and time

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Bruschetta Do you mean you want a tool-bar in your dialog?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Bruschetta Do you mean you want a tool-bar in your dialog?

        B Offline
        B Offline
        Bruschetta
        wrote on last edited by
        #3

        @jsulm

        Yes, this is the goal i'm trying to achieve

        jsulmJ 1 Reply Last reply
        0
        • B Bruschetta

          @jsulm

          Yes, this is the goal i'm trying to achieve

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Bruschetta What about http://doc.qt.io/qt-5/qtoolbar.html ?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • joeQJ Offline
            joeQJ Offline
            joeQ
            wrote on last edited by
            #5

            @Bruschetta Hi, friend, welcome.
            There is QToolBar Application Example.

            Just do it!

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Bruschetta
              wrote on last edited by
              #6

              Thak you guys but i already have a QToolbar in my mainwindow and for what i undestood inserting a Qtoolbar into a dialog is not possilbe.
              Infact there is no "addToolBar()" method, method that is present in the main window.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bruschetta
                wrote on last edited by
                #7

                I found how to do what i wanted to do.
                Here some code for the ones who may have the same "problem"

                //into the Dialog
                QMainWindow * mainWindow = new QMainWindow(); 
                
                QToolBar * myToolBar = new QToolBar();
                myToolBar->setIconSize( QSize( 32, 32 ) );
                myToolBar->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
                
                QPixmap newpix = QPixmap (":/x.png");
                myToolBar->addAction(QIcon(newpix), "bla");
                
                mainWindow->addToolBar(myToolBar);
                
                QHBoxLayout * layout = new QHBoxLayout();
                layout->addWidget(mainWindow);
                setLayout(layout);
                
                1 Reply Last reply
                1

                • Login

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