案例2:绘制按钮
main.cpp
#include<QApplication>
#include “demoWidget.h”
int main(int args , int argv)
{
QApplication app(args , argv);
DemoWidget w;
w.resize(400,400);
w.setVisible(true);
return app.exec();
}
main.pro
TEMPLATE=app
SOURCES=main.cpp demoWidget.cppdemoPushButton.cpp
HEADERS=demoWidget.h demoPushButton.h
CONFIG=release qt
QT=core gui
TARGET=main
demoWidget.h
#ifndef DEMO2_WIDGET_H
#define DEMO2_WIDGET_H
#include<QWidget>
#include “demoPushButton.h”
class DemoWidget: public QWidget
{
public:
DemoWidget(QWidget * parent=NULL);
public:
DemoPushButton * btn;
};
#endif
demoWidget.cpp
#include “demoWidget.h”
#include “demoPushButton.h”
DemoWidget::DemoWidget(QWidget *parent):QWidge

本文通过一个案例展示了如何使用QT进行自定义按钮的绘制,包括在`paintEvent`中绘制边框,`enterEvent`和`leaveEvent`处理鼠标进入和离开事件改变按钮状态,以及`mouseEvent`响应鼠标点击事件。代码中详细解释了各个函数的作用和实现过程。
最低0.47元/天 解锁文章
612

被折叠的 条评论
为什么被折叠?



