1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 设置QPushButton的背景图片

设置QPushButton的背景图片

时间:2020-05-01 00:35:14

相关推荐

设置QPushButton的背景图片

setIcon(QIcon("toolbutton.png"));

setIconSize(QSize(48, 48));

如果没有下面那句话,该图片是被缩放的放到图片上

如果加上下面那句话这该图片的背景图被设置为当前尺寸

如果不是按钮可以用调色板来实现

QPalette p = palette();

p.setBrush(QPalette::Button, QBrush(QPixmap("toolbutton.png")));

setPalette(p);

注意:setBrush的第一个参数文档上是这样说的:

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:

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.

Selected (marked) items have two roles:

There are two color roles related to hyperlinks:

Note that we do not use theLinkandLinkVisitedroles when rendering rich text in Qt, and that we recommend that you use CSS and the QTextDocument::setDefaultStyleSheet() 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);

说明:每次遇到有点坑爹的问题时,不要一上来到网上狂搜,先看一下api文档嘛!这不?别人说的很清除的。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。