Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将Button_SetElevationRequiredState与QPushButton一起使用?_C++_Windows_Qt_Winapi - Fatal编程技术网

C++ 如何将Button_SetElevationRequiredState与QPushButton一起使用?

C++ 如何将Button_SetElevationRequiredState与QPushButton一起使用?,c++,windows,qt,winapi,C++,Windows,Qt,Winapi,我试过这个: QPushButton* openHostsPushButton = new QPushButton("Open Hosts"); Button_SetElevationRequiredState(openHostsPushButton->winId(), true); openHostsPushButton->setMaximumSize(aPushButtonMaxSize); connect(openHostsPushButton, SIGNAL(clicked(

我试过这个:

QPushButton* openHostsPushButton = new QPushButton("Open Hosts");
Button_SetElevationRequiredState(openHostsPushButton->winId(), true);
openHostsPushButton->setMaximumSize(aPushButtonMaxSize);
connect(openHostsPushButton, SIGNAL(clicked()),
        this, SLOT(openHostsClicked()));

但是没有起作用。

我不确定这是否会起作用,因为Qt实际上并不使用本机控件,而是自定义绘制所有内容。Windows将该图标放置在按钮上的唯一方法是使用带有类
按钮的窗口,这是您要求窗口管理器为您创建的

还要注意的是,为了使其正常工作,您必须在应用程序中包含一个清单,以链接到通用控件(Comctl32.dll)的版本6,但如果您支持Windows Vista和7,您可能已经这样做了

但使用Qt有一种更简单的方法:

在不支持UAC的系统上,图标将不会出现。

setIcon()
很好,但是否有方法从windows按钮创建QPushButton?
QIcon shieldIcon = QApplication::style()->standardIcon(QStyle::SP_VistaShield);
openHostsPushButton->setIcon(shieldIcon);