对齐QMenuBar项(在左侧添加一些,在右侧添加一些) [英] Aligning QMenuBar items (add some on left and some on right side)
本文介绍了对齐QMenuBar项(在左侧添加一些,在右侧添加一些)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我有带有三个QAction的QMenuBar,它看起来像这样:
Currently I have QMenuBar with three QActions and it looks like this:
但是我想得到这个(获取一些QAction右对齐):
but I would like to get this (get some QActions right-aligned):
有没有办法做到这一点?
Is there a way to do this?
推荐答案
Well one possible solution is here. But it involves implementing your own style (QStyle as I recall). However here is a snippet that I have just tried on mainwindow class:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
ui->setupUi(this);
QMenuBar *barLeft = new QMenuBar;
QMenuBar *barRight = new QMenuBar;
barLeft->addAction("Foo Left 1");
barLeft->addAction("Foo Left 2");
barRight->addAction("Foo Left 1");
barRight->addAction("Foo Left 2");
QHBoxLayout *mainMenuLayout = new QHBoxLayout;
mainMenuLayout->addWidget(barLeft);
mainMenuLayout->addWidget(barRight);
mainMenuLayout->setAlignment(barLeft, Qt::AlignLeft);
mainMenuLayout->setAlignment(barRight, Qt::AlignRight);
QWidget *central = new QWidget;
central->setLayout(mainMenuLayout);
setCentralWidget(central);
}
这应该合适.
这篇关于对齐QMenuBar项(在左侧添加一些,在右侧添加一些)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文