Set the background image of qpushbutton

Source: Internet
Author: User

Seticon (qicon ("toolbutton.png "));
Seticonsize (qsize (48, 48 ));

If there is no such sentence, the image is scaled and placed on the image.

If the following sentence is added, the background image of the image is set to the current size.

 

You can use a color palette if it is not a button.

Qpalette P = palette ();
P. setbrush (qpalette: button, qbrush (qpixmap ("toolbutton.png ")));
Setpalette (P );

Note: The first parameter document of setbrush says this:

Void qpalette: setbrush (colorroleRole, Const qbrush &Brush);

Enum qpalette: colorrole

The colorrole Enum defines the different symbolic color roles used in current guis.

The central roles are:

Constant Value Description
Qpalette: Window 10 A general background color.
Qpalette: Background Window This value is obsolete. Use Window instead.
Qpalette: windowtext 0 A general foreground color.
Qpalette: foreground Windowtext This value is obsolete. Use windowtext instead.
Qpalette: Base 9 Used mostly as the background color for text entry widgets, but can also be used for other painting-such as the background of ComboBox drop down lists and toolbar handles. it is usually white or another light color.
Qpalette: alternatebase 16 Used as the alternate background color in views with alternating row colors (see q1_actitemview: setalternatingrowcolors ()).
Qpalette: tooltipbase 18 Used as the background color for qtooltip and qwhatsthis.
Qpalette: tooltiptext 19 Used as the foreground color for qtooltip and qwhatsthis.
Qpalette: Text 6 The foreground color usedBase. This is usually the same asWindowtext, In which case it must provide good contrastWindowAndBase.
Qpalette: button 1 The general button background color. This background can be different fromWindowAs some styles require a different background color for buttons.
Qpalette: buttontext 8 A foreground color used withButtonColor.
Qpalette: brighttext 7 A text color that is very different fromWindowtext, And contrasts well with e.g.Dark. Typically used for text that needs to be drawn whereTextOrWindowtextWocould give poor contrast, such as on pressed
Push buttons. Note that text colors can be used for things other than just words; text colors areUsuallyUsed for text, but it's quite common to use the text color roles for lines, icons, etc.

There are some color roles used mostly for 3D Bevel and shadow effects. All of these are normally derived fromWindow, And used in ways that depend on that relationship. For example, buttons depend on it to make the bevels look attractive, and Motif
Scroll bars depend onMidTo be slightly different fromWindow.

Constant Value Description
Qpalette: Light 2 LighterButtonColor.
Qpalette: midlight 3 BetweenButtonAndLight.
Qpalette: dark 4 DarkerButton.
Qpalette: Mid 5 BetweenButtonAndDark.
Qpalette: Shadow 11 A very dark color. By default, the shadow color is QT: black.

Selected (marked) items have two roles:

Constant Value Description
Qpalette: highlight 12 A color to indicate a selected item or the current item. By default, the highlight color is QT: darkblue.
Qpalette: highlightedtext 13 A text color that contrastsHighlight. By default, the highlighted text color is QT: white.

There are two color roles related to hyperlinks:

Constant Value Description
Qpalette: Link 14 A text color used for unvisited hyperlinks. By default, the link color is QT: Blue.
Qpalette: linkvisited 15 A text color used for already visited hyperlinks. By default, the linkvisited color is QT: magenta.

Note that we do not useLinkAndLinkvisitedRoles when rendering Rich Text in QT, and that we recommend that you use CSS and the qtextdocument: setdefastystylesheet () function to alter
The appearance of links. For example:

     QTextBrowser browser;     QColor linkColor(Qt::red);     QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(linkColor.name());     browser.document()->setDefaultStyleSheet(sheet);
Constant Value Description
Qpalette: norole 17 No role; this special role is often used to indicate that a role has not been assigned.

Note: When you encounter a problem, do not go online and search for the API documentation first! No? What others say is very clear.

From http://blog.csdn.net/zgrjkflmkyc/article/details/9042333

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.