关于Qt的动态效果的button
现在我有一份代码,但我不会具体怎么使用。请问Qt大神能给我一个具体使用的例子吗。代码如下:Button::Button(QWidget*parent):QPushButt...
现在我有一份代码,但我不会具体怎么使用。请问Qt大神能给我一个具体使用的例子吗。代码如下:
Button::Button(QWidget *parent) : QPushButton(parent)
{
//保存图片成员初始化
buttonPicture = new QPixmap();
pressPicture = new QPixmap();
releasePicture = new QPixmap();
//关闭按钮的默认显示
this -> setFlat(true);
}
void Button::setButtonPicture(QPixmap pic)
{
*buttonPicture = pic;
this -> setIcon(QIcon(*buttonPicture));
}
void Button::setPressPicture(QPixmap pic)
{
*pressPicture = pic;
}
void Button::setReleasePicture(QPixmap pic)
{
*releasePicture = pic;
}
void Button::set_X_Y_width_height(int x, int y, int width, int height)
{
this -> setIconSize(QSize(width, height));
this -> setGeometry(x, y, width, height);
}
void Button::mouseDoubleClickEvent(QMouseEvent *event)
{
//null
}
void Button::mousePressEvent (QMouseEvent *event)
{
this -> setIcon (QIcon(*pressPicture));
}
void Button::mouseMoveEvent(QMouseEvent *event)
{
//null
}
void Button::mouseReleaseEvent (QMouseEvent *event)
{
this -> setIcon(QIcon(*releasePicture));
emit clicked();
} 展开
Button::Button(QWidget *parent) : QPushButton(parent)
{
//保存图片成员初始化
buttonPicture = new QPixmap();
pressPicture = new QPixmap();
releasePicture = new QPixmap();
//关闭按钮的默认显示
this -> setFlat(true);
}
void Button::setButtonPicture(QPixmap pic)
{
*buttonPicture = pic;
this -> setIcon(QIcon(*buttonPicture));
}
void Button::setPressPicture(QPixmap pic)
{
*pressPicture = pic;
}
void Button::setReleasePicture(QPixmap pic)
{
*releasePicture = pic;
}
void Button::set_X_Y_width_height(int x, int y, int width, int height)
{
this -> setIconSize(QSize(width, height));
this -> setGeometry(x, y, width, height);
}
void Button::mouseDoubleClickEvent(QMouseEvent *event)
{
//null
}
void Button::mousePressEvent (QMouseEvent *event)
{
this -> setIcon (QIcon(*pressPicture));
}
void Button::mouseMoveEvent(QMouseEvent *event)
{
//null
}
void Button::mouseReleaseEvent (QMouseEvent *event)
{
this -> setIcon(QIcon(*releasePicture));
emit clicked();
} 展开
1个回答
展开全部
一个简单例子:
class Button;
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
private:
Button *botton;
};
//实现方法
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
botton = new Button(this);
botton->set_X_Y_width_height(10,10,80,30); //设置button停靠位置和大小
//设置button原图片,按下时图片,抬起时图片
botton->setButtonPicture(QPixmap("d:\\1.png"));
botton->setPressPicture(QPixmap("d:\\2.png"));
botton->setReleasePicture(QPixmap("d:\\3.png"));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询