Praneeth Peiris
Praneeth Peiris

Reputation: 2088

Simple way to get the current docked area of a QToolbar

I'm working on a Qt project, where I need to get the toolbar positions at run-time. Is there any way to get the current positioning of a QToolbar inside a QMainWindow ?

Thanks.

EDIT:

Thanks for the answer and I got 75% working. But there is a problem in QMainWindow::toolBarArea(QToolBar * toolbar).

When I dock two toolbars in a single area (i.e. Bottom area), as below.

-----------------------------------
| Toolbar 1                       |
-----------------------------------
| Toolbar 2                       |
-----------------------------------

Then I save the area obtained from QMainWindow::toolBarArea, using QSettings and then load them back, it loads as below.

-----------------------------------
| Toolbar 1      | Toolbar 2      |
-----------------------------------

Is there any way to stop that as well?

Upvotes: 0

Views: 1378

Answers (1)

Tay2510
Tay2510

Reputation: 5978

Within the scope of QMainWindow, you can call QMainWindow::toolBarArea(QToolBar *toolbar) to get the toolbar position.

Returns the Qt::ToolBarArea for toolbar. If toolbar has not been added to the main window, this function returns Qt::NoToolBarArea.

It returns the enum:

enum ToolBarArea {
        LeftToolBarArea = 0x1,
        RightToolBarArea = 0x2,
        TopToolBarArea = 0x4,
        BottomToolBarArea = 0x8,

        ToolBarArea_Mask = 0xf,
        AllToolBarAreas = ToolBarArea_Mask,
        NoToolBarArea = 0
    };

Upvotes: 1

Related Questions