Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you add a toolbar to QDialog?

I'm working on a project that needs to call a modal window with a toolbar to do some work on some data before it's loaded. The reason I need the toolbar is the user has a few different possible options that can be combined.

The obvious choice here is a Modal dialog (which I have working right now). The issue is I want a toolbar. This is a two part question:

  1. Is it possible to add a toolbar to a QDialog? (also is it possible to do this in Qt Designer?)
  2. If 1. is not possible, how can I make a QMainWindow modal?
like image 796
John Avatar asked Aug 26 '13 02:08

John


1 Answers

You can add QToolBar in QDialog. But as a QWidget. Please have a look

MyDialog::MyDialog(QWidget *parent) : QDialog(parent)
{
   QVBoxLayout *mainLayout = new QVBoxLayout(this);

   QToolBar *toolBar = new QToolBar();
   mainLayout->addWidget(toolBar);

   QAction *action1 = new QAction("Add", toolBar);
   QAction *action1 = new QAction("Del", toolBar);

  //Add What you want
}

As QToolBar is child of QWidget we can add it as Widget. Using Layout you can adjust its position. Please check this link http://developer.nokia.com/community/wiki/How_to_use_QToolBar_and_QToolButton_in_Qt

like image 93
DigviJay Patil Avatar answered Sep 20 '22 03:09

DigviJay Patil