How do you know it isn't working? Did you put a breakpoint on the line with the refresh() call? Or at least add a qDebug() statement inside the if clause to show it is being entered?But looks like there is something wrong in the if condition. Its not working.
Any changes to the text on the buttons will not occur until after the keyPressEvent() is done and control has returned to the event loop so the buttons can receive their paintEvent() messages.
Bookmarks