QAbstractButton
QAbstractButton
自定义button
设置属性
| 函数 | 描述 |
|---|---|
| void setCheckable(bool) | 可选设置 |
| void setChecked(bool) | 选择 |
| void setDown(bool) | button按下 |
| void setIcon(const QIcon &icon) | |
| void setShortcut(const QKeySequence &key) | |
| void setText(const QString &text) |
void seticoSize()
判断
| 函数 | 描述 |
|---|---|
| bool isCheckable() const | 可选判断 |
| bool isChecked() const | 是否选中 |
| bool isDown() const | 是否按下 |
slots
void animateClick(int msec = 100)
void click()
void setChecked(bool)
void setIconSize(const QSize &size)
void toggle()
sinals
void clicked(bool checked = false)
void pressed()
void released()
void toggled(bool checked)
小例子
mywidget::mywidget()
{
loadstyle::setstyle(":/image/myqss.qss");
setWindowTitle("my widget test");
QVBoxLayout *layout=new QVBoxLayout(this);
QAbstractButton *pbutton1=new QPushButton("button1");
pbutton1->setIcon(QIcon(":/image/wz2.jpg")); //设置图标
pbutton1->setIconSize(QSize(20,29)); //图标大小
pbutton1->setCheckable(true); //设置可选中
pbutton1->setChecked(true); //选中中
pbutton1->setShortcut(Qt::Key_Home);
connect(pbutton1,&QPushButton::clicked,[]{qDebug()<<"Enter....";});
layout->addWidget(pbutton1);
this->setFixedSize(300,300);
this->show();
}

浙公网安备 33010602011771号