Search code examples
qtmacosdefaultbutton

Qt default button on mac


Mac have a capability to specify two default buttons, one activated by return and other by spacebar. One clear example is when you press power button on mac. It gives you a dialog box with quiet a few buttons, in which it shutdown is default for return key and restart is default for spacebar key. Is it possible to achieve such effect in Qt?


Solution

  • Yes.

    Use QPushButton. On the "default" button use setDefault and setAutoDefault() to make them appear as a default button.

    http://doc.trolltech.com/4.7/qpushbutton.html#default-prop

    To handle the escape key (and possibly even the return key), you must set the shortcuts for each button to associate them with a corresponding key. It's easy to do that using Qt Creator/Designer.