How do I set QMenu to align to the right of a toolbar?

后端 未结 1 1796
旧时难觅i
旧时难觅i 2021-01-25 23:21

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 c

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-25 23:51

    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 hint, const QStyleOption * option, const QWidget * widget, 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); 
    

    0 讨论(0)
提交回复
热议问题