Results 1 to 5 of 5

Thread: Vista/Win7 UAC Shield Icon on QPushButton?

  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Vista/Win7 UAC Shield Icon on QPushButton?

    With a standard Windows app, linked to Common Controls 6, you do:
    Qt Code:
    1. GetDlgItem(IDC_SOMEBUTTONID)->SendMessage(BCM_SETSHIELD, 0, TRUE);
    To copy to clipboard, switch view to plain text mode 
    and the appropriately coloured shield icon is added to your button.

    Is there a way to get the "official" Windows UAC shield icon on to a QPushButton?
    Is shipping an icon for each of Vista and Win 7 (different colours) and manually applying it the only way with Qt?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Vista/Win7 UAC Shield Icon on QPushButton?

    Did you try using the above call with QPushButton? You would have to get the winID() of the button, then convert it to Windows handle to have something you can send a message to and then send the message.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Vista/Win7 UAC Shield Icon on QPushButton?

    Yes I had, but I just went back and tried again (I initially missed the second step). I've added this incantation to the Windows application manifest:
    Qt Code:
    1. ...
    2. <dependency>
    3. <dependentAssembly>
    4. <assemblyIdentity
    5. type="win32"
    6. name="Microsoft.Windows.Common-Controls"
    7. version="6.0.0.0"
    8. processorArchitecture="X86"
    9. publicKeyToken="6595b64144ccf1df"
    10. language="*"
    11. />
    12. </dependentAssembly>
    13. </dependency>
    14. ...
    To copy to clipboard, switch view to plain text mode 
    and this snippet at the front of the application main
    Qt Code:
    1. INITCOMMONCONTROLSEX iccex;
    2. iccex.dwSize = sizeof(iccex);
    3. iccex.dwICC = ICC_STANDARD_CLASSES;
    4. BOOL ret = ::InitCommonControlsEx(&iccex);
    5. if (ret != 0)
    6. qDebug() << "::InitCommonControlsEx() success";
    To copy to clipboard, switch view to plain text mode 
    and this in the constructor for the form:
    Qt Code:
    1. static const UINT BCM_SETSHIELD = 0x160C; //Elevated button
    2.  
    3. WId id = widget->winId();
    4. (void) ::SendMessage(id, BCM_SETSHIELD, 0, TRUE);
    5. }
    To copy to clipboard, switch view to plain text mode 
    and still no shield icon (Win7). I am guessing that Qt is drawing the control without reference to Windows; but it just a guess.

    At the moment it looks like my best option is to load the shield icon resource from the Windows file that contains it and try to get it into a QIcon (via a QPixmap perhaps). Haven't the time to try this right now though.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Vista/Win7 UAC Shield Icon on QPushButton?

    I was hoping that handling this message was done by Windows and not by the button object but it looks like it's not the case.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Vista/Win7 UAC Shield Icon on QPushButton?

    For future reference the answer was lurking in QStyle:
    Qt Code:
    1. QIcon icon = QApplication::style()->standardIcon(QStyle::SP_VistaShield);
    2. QPixmap pixmap = icon.pixmap(32, 32, QIcon::Normal, QIcon::On);
    3.  
    4. QLabel label;
    5. label.setPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 
    The icon is null on non-Vista/7 systems.

Similar Threads

  1. Replies: 0
    Last Post: 27th April 2010, 16:15
  2. QPushButton - Only show the Icon
    By graciano in forum Newbie
    Replies: 9
    Last Post: 19th September 2009, 22:15
  3. Problems with QPushButton displaying an icon
    By John82 in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2009, 18:42
  4. QPushButton Icon Image
    By QbelcorT in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 15:26
  5. Stretching Icon in QPushButton
    By dsandber in forum Qt Tools
    Replies: 1
    Last Post: 6th October 2007, 17:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.