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. How to make buttons in Place of Menubar in QT?
Forum Updated to NodeBB v4.3 + New Features

How to make buttons in Place of Menubar in QT?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 315 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.
  • Aviral 0A Offline
    Aviral 0A Offline
    Aviral 0
    wrote on last edited by
    #1

    Screenshot (231).png
    In Place of File dropdown Menubar, I want direct Buttons in menubar which I have sketched in the picture.

    This is my MainWindow.cpp class:

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent),
          model(new DomModel(QDomDocument(), this)),
          view(new QTreeView(this))
    {
        fileMenu = menuBar()->addMenu(tr("&File"));
        fileMenu->addAction(tr("&FIND"), this, &MainWindow::openFile, QKeySequence::Open);
        //fileMenu->addAction(tr("E&xit"), this, &QWidget::close, QKeySequence::Quit);
        //fileMenu = activeAction(tr("&FIND"), this, &MainWindow::openFile, QKeySequence::Open);
    
        view->setModel(model);
    
        setCentralWidget(view);
        setWindowTitle(tr("QTreeViewXML"));
    
    }
    void MainWindow::openFile()
    {
    QString filePath = QFileInfo("C:\\Users\\arpit.k\\Documents\\QT\\build-QTreeViewXML-Desktop_Qt_6_2_4_MinGW_64_bit-Debug\\Sample.xml").absoluteFilePath();
    
        if (!filePath.isEmpty()) {
            QFile file(filePath);
            if (file.open(QIODevice::ReadOnly)) {
                QDomDocument document;
                if (document.setContent(&file)) {
                    DomModel *newModel = new DomModel(document, this);
                    view->setModel(newModel);
                    delete model;
                    model = newModel;
                    xmlPath = filePath;
                }
                file.close();
            }
        }
    }
    
    1 Reply Last reply
    0
    • Aviral 0A Aviral 0

      @mpergand Thankyou for suggestion.
      Please help me write the Qtoolbar code, or atleast help me initiate it.
      I tried my own many times but now able to write it right. and I didn't find any resource online with syntax or example. Please Help~!

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

      @Aviral-0 said in How to make buttons in Place of Menubar in QT?:

      I tried my own many times but now able to write it right

      Please show what you did.
      https://doc.qt.io/qt-6/qtwidgets-mainwindows-application-example.html shows how to do this...

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

      Aviral 0A 1 Reply Last reply
      1
      • M Offline
        M Offline
        mpergand
        wrote on last edited by mpergand
        #2

        Use QToolBar instead.

        Aviral 0A 1 Reply Last reply
        0
        • M mpergand

          Use QToolBar instead.

          Aviral 0A Offline
          Aviral 0A Offline
          Aviral 0
          wrote on last edited by
          #3

          @mpergand Thankyou for suggestion.
          Please help me write the Qtoolbar code, or atleast help me initiate it.
          I tried my own many times but now able to write it right. and I didn't find any resource online with syntax or example. Please Help~!

          jsulmJ 1 Reply Last reply
          0
          • Aviral 0A Aviral 0

            @mpergand Thankyou for suggestion.
            Please help me write the Qtoolbar code, or atleast help me initiate it.
            I tried my own many times but now able to write it right. and I didn't find any resource online with syntax or example. Please Help~!

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

            @Aviral-0 said in How to make buttons in Place of Menubar in QT?:

            I tried my own many times but now able to write it right

            Please show what you did.
            https://doc.qt.io/qt-6/qtwidgets-mainwindows-application-example.html shows how to do this...

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

            Aviral 0A 1 Reply Last reply
            1
            • jsulmJ jsulm

              @Aviral-0 said in How to make buttons in Place of Menubar in QT?:

              I tried my own many times but now able to write it right

              Please show what you did.
              https://doc.qt.io/qt-6/qtwidgets-mainwindows-application-example.html shows how to do this...

              Aviral 0A Offline
              Aviral 0A Offline
              Aviral 0
              wrote on last edited by
              #5

              @jsulm Thankyou! It worked.

              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