问题描述
在我的 Qt 工具栏上,我有几个 QMenu(默认情况下所有这些都向左对齐).我想让其中一个与右侧对齐,但我似乎找不到正确的方法来做到这一点.有什么想法吗?
On my toolbar in Qt, I have several QMenus (all of which align to the left by default). I would like to make one of them align to the right side, but I can't seem to find the correct way to do this. Any ideas?
推荐答案
QMotifStyle 给了我答案.在这种风格中,在菜单栏中添加分隔符后,后续菜单将添加到菜单的右侧.解决方案是使用编写一个 QStyle 代理类,但重载一个方法:styleHint,以在 SH_DrawMenuBarSeparator 上返回 true(这就是 QMotifStyle 所做的).
QMotifStyle gave me the answer. In that style, after adding a separator in the menubar, subsequent menus are added to the right hand side of the menu. The solution was to use write a QStyle proxy class, but overload one method: styleHint, to return true on SH_DrawMenuBarSeparator (which is what QMotifStyle does).
int MyStyle::styleHint( StyleHint 提示,const QStyleOption * 选项,const QWidget * 小部件,QStyleHintReturn * returnData) const
// Return true on menu bar separator so subsequent menu bars are
// drawn on the right side of the bar!
if ( hint == SH_DrawMenuBarSeparator)
return true;
else
return style->styleHint(hint, option, widget, returnData);
这篇关于如何将 QMenu 设置为与工具栏的右侧对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!