(Solved) Accelerator (&) for DzPushButton added to DzButtonGroup not showing underlined?

The docs indicate that for the text property of DzButton (inherited by DzPushButton):

An ampersand (&) in the String automatically creates an accelerator for it using the character that follows the ampersand, as the accelerator key.


btn.text = "&OK";

produces:  OK   It works fine on its own.

However, when I add a DzPushButton to a DzButtonGroup and assign its text property, the ampersand shows up with the text, instead of underlining the accelerator character when the button is displayed:   &OK


Am I missing something obvious?

BTW, I'm using

var btn = new DzPushButton(wBtnGroup);

btn.text = "&Something with an ampersand";

 to create the buttons directly as children of the button group.

Thanks in advance...

Post edited by ghost_of_delete_key on


  • edited September 2021

    I've found the solution after a bit of a fishing expedition through the QT docs.

    Somehow, creating the DzPushButton with a DzButtonGroup as parent breaks the buttonTextFormat property, as described in OP.

    To fix the ampersand appearing (although the accelerator works), the proper flags must be explicitly reset.

    https://doc.qt.io/archives/qt-4.8/qt.html#AlignmentFlag-enum and https://doc.qt.io/archives/qt-4.8/qt.html#TextFlag-enum together list the flags that must be OR-ed together to create the desired text display.

    In this case, keeping the default center-alignment of text, and displaying the underline for the accelerator, needs AlignHCenter, AlignVCenter and TextShowMnemonic to be assigned to the button's property.


    var btn = new DzPushButton(wBtnGroup);
    btn.text = "&OK";
    btn.buttonTextFormat = (0x0004|0x0080|0x0800);

    works perfectly.


    Hope this helps someone sometime.



    Post edited by ghost_of_delete_key on
Sign In or Register to comment.