I tried this:
QPushButton* openHostsPushButton = new QPushButton("Open Hosts");
Button_SetElevationRequiredState(openHostsPushButton->winId(), true);
openHostsPushButton->setMaximumSize(aPushButtonMaxSize);
connect(openHostsPushButton, SIGNAL(clicked()),
this, SLOT(openHostsClicked()));
However didn’t work.
I’m not sure if this will work, since Qt doesn’t actually use native controls but rather custom-draws everything. The only way that Windows will place that icon on a button is if you use a window with the class
Button, something that you ask the window manager to create for you.Also note that in order for this to work, you must have included a manifest with your application to link to version 6 of the common controls (Comctl32.dll)—but you should probably be doing that already if you’re supporting Windows Vista and 7.
But there’s an easier way to do it using Qt involving
QStyle:On systems that do not support UAC, the icon will not appear.