Vertical QToolBar from MainWindow

不想你离开。 提交于 2021-02-07 21:57:25

问题


What I want: http://puu.sh/3oUjh.jpg What I have: http://puu.sh/3oUnI.png

The toolbar is made in mainwindow.ui, ive tried ui->_toolbar->setLayoutDirection(Qt::LeftToolBarArea);

But I get this error: no matching function for call to 'QToolBar::setLayoutDirection(Qt::ToolBarArea)'


回答1:


You can use QToolBar::orientation property:

ui->myToolbar->setOrientation(Qt::Vertical);

You can also use QMainWindow::addToolBar:

addToolBar(Qt::LeftToolBarArea, ui->myToolbar);

Note that by default the user is able to drag toolbars and attach them to any side of the main window.




回答2:


You're using the wrong enum for setLayoutDirection:

// Don't use this.  You need to use a different method 
// if you want it placed against the left side.
enum ToolBarArea {
    LeftToolBarArea = 0x1,
    RightToolBarArea = 0x2,
    TopToolBarArea = 0x4,
    BottomToolBarArea = 0x8,

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

You need to use something from Qt::LayoutDirection:

enum LayoutDirection {
    LeftToRight,
    RightToLeft,
    LayoutDirectionAuto
};

ui->_toolbar->setLayoutDirection(Qt::LeftToRight);


来源:https://stackoverflow.com/questions/17327838/vertical-qtoolbar-from-mainwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!