当前位置:编程学习 > wap >>

新手在美化按钮时出现问题~请求支援~~

已经写了一个Dialog登陆框,加了背景,想让“登录”按钮更好看些。现在想将一个QPushButton美化,具体操作就是创建一个类,让这个PushButton在鼠标点击、释放、保持的时候有不同的表现。用贴不同的图来实现。就是念茜日志里面的方法。

于是自己写了一下
#include "loginbutton.h"
#include <QPushButton>

LoginButton::LoginButton(QWidget *parent) :
    QPushButton(parent)
{
    //保存图片成员初始化
    QPixmap *buttonPicture = new QPixmap();
    QPixmap *pressPicture = new QPixmap();
    QPixmap *releasePicture = new QPixmap();

            //关闭按钮的默认显示
            this -> setFlat(true);
            this->setFocusPolicy(Qt::NoFocus);
}
void LoginButton::setButtonPicture(QPixmap pic)
{
        *buttonPicture = pic;

        this -> setIcon(QIcon(*buttonPicture));
}

void LoginButton::setPressPicture(QPixmap pic)
{
        *pressPicture = pic;
}

void LoginButton::setReleasePicture(QPixmap pic)
{
        *releasePicture = pic;
}

void LoginButton::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 LoginButton::mousePressEvent (QMouseEvent *event)
{
        this -> setIcon (QIcon(*pressPicture));
}
void LoginButton::mouseReleaseEvent (QMouseEvent *event)
{
        this -> setIcon(QIcon(*releasePicture));
        emit clicked();
}

结果报了一堆错……完全混乱不知道怎么回事,请帮帮忙
--------------------编程问答-------------------- 你的类声明了这些函数了嘛
void LoginButton::setButtonPicture(QPixmap pic)
{
        *buttonPicture = pic;
 
        this -> setIcon(QIcon(*buttonPicture));
}
 
void LoginButton::setPressPicture(QPixmap pic)
{
        *pressPicture = pic;
}
 
void LoginButton::setReleasePicture(QPixmap pic)
{
        *releasePicture = pic;
}
 
void LoginButton::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 LoginButton::mousePressEvent (QMouseEvent *event)
{
        this -> setIcon (QIcon(*pressPicture));
}
void LoginButton::mouseReleaseEvent (QMouseEvent *event)
{
        this -> setIcon(QIcon(*releasePicture));
        emit clicked();
} --------------------编程问答-------------------- 哎呀~没注意~~

现在在头文件private里面声明了。
出现了这些 --------------------编程问答-------------------- 1楼说的没错。
把头文件也贴出来吧。 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 目测你的头文件没有继承QPushButton --------------------编程问答-------------------- 继承写错了吧
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,