新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正
一、按键包括图片与文字,以文字的方向设定。
使用QToolButton按键创建对象
textAndImage::textAndImage(QWidget *parent) :QMainWindow(parent),
ui(new Ui::textAndImage)
{
ui->setupUi(this);
ui->refreshToolButton->setText(tr("刷新"));
ui->refreshToolButton->setIcon(QPixmap(":/image/10IK012614.png"));
ui->refreshToolButton->setIconSize(QPixmap(":/image/10IK012614.png").size());
ui->refreshToolButton->setAutoRaise(true);
ui->refreshToolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
ui->musictoolbutton->setText(tr("音乐"));
ui->musictoolbutton->setIcon(QPixmap(":/image/10IK05Q25.png"));
ui->musictoolbutton->setIconSize(QPixmap(":/image/10IK05Q25.png").size());
ui->musictoolbutton->setAutoRaise(true);
ui->musictoolbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
ui->stoptoolbutton->setText(tr("暂停"));
ui->stoptoolbutton->setIcon(QPixmap(":/image/10IK0M92.png"));
ui->stoptoolbutton->setIconSize(QPixmap(":/image/10IK0M92.png").size());
ui->stoptoolbutton->setAutoRaise(true);
ui->stoptoolbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
ui->powertoolbutton->setText(tr("电源"));
ui->powertoolbutton->setIcon(QPixmap(":/image/10IK0M28.png"));
ui->powertoolbutton->setIconSize(QPixmap(":/image/10IK0M28.png").size());
ui->powertoolbutton->setAutoRaise(true);
ui->powertoolbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
ui->soundtoolbutton->setText(tr("声音"));
ui->soundtoolbutton->setIcon(QPixmap(":/image/10IK05F9.png"));
ui->soundtoolbutton->setIconSize(QPixmap(":/image/10IK05F9.png").size());
ui->soundtoolbutton->setAutoRaise(true);
ui->soundtoolbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
}
二、sheetstyle风格的设置。
QString sheetStyle = "QToolButton{background-color:rgb(80,180,200);color:rgb(56, 49, 255);border-radius:12px;border:2px groove gray;border-style:outset;font: 75 12pt Ubuntu;}"\
"QToolButton:hover{background-color:white;color:black;}"\
"QToolButton:pressed{background-color:rgb(85,170,255);border-style:inset;}";
int main(int argc, char *argv[])
{
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QApplication a(argc, argv);
QStyleFactory style;
a.setStyle(style.create(sheetStyle));
a.setStyleSheet(sheetStyle);
textAndImage w;
w.show();
return a.exec();
}
三、鼠标停留表现备注
在qt creator中选中对象,进入其属性设置对话框,双击“toolTip选项”,就可以停止设置了,如图:
四、最后按键的效果图如下:
文章结束给大家分享下程序员的一些笑话语录: 这年头的互联网真是娱乐了中国,网民们从各种各样的“门”里钻来钻去,又有好多“哥”好多“帝”,值得大家品味不已……网络经典语录,关于IT与互联网,经典与您分享!
--------------------------------- 原创文章 By
设置和文字
---------------------------------