How to make buttons in Place of Menubar in QT?
-
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(); } } }
-
@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... -
@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~! -
@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...