41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
|
|
#include "APP/APP_GlassCard.h"
|
|||
|
|
|
|||
|
|
#include <QtGui/QPainter>
|
|||
|
|
|
|||
|
|
namespace APP {
|
|||
|
|
|
|||
|
|
APP_GlassCard::APP_GlassCard(QWidget* parent)
|
|||
|
|
: QFrame(parent)
|
|||
|
|
{
|
|||
|
|
// 交给我们自己统一绘制卡片外观,不使用 QFrame 默认边框。
|
|||
|
|
setFrameShape(QFrame::NoFrame);
|
|||
|
|
// 背景由 paintEvent 自绘,这里不走样式表背景。
|
|||
|
|
setAttribute(Qt::WA_StyledBackground, false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void APP_GlassCard::paintEvent(QPaintEvent* event)
|
|||
|
|
{
|
|||
|
|
Q_UNUSED(event);
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
* 卡片外观刻意保持简单,方便教学时理解自绘流程:
|
|||
|
|
* 1. 先画一个带圆角的深色底板
|
|||
|
|
* 2. 再画一圈细边框
|
|||
|
|
*/
|
|||
|
|
const QRectF BodyRect = rect().adjusted(1.0, 1.0, -1.0, -1.0);
|
|||
|
|
const qreal Radius = 22.0;
|
|||
|
|
const QColor FillColor(30, 35, 43);
|
|||
|
|
const QColor BorderColor(82, 92, 104);
|
|||
|
|
|
|||
|
|
QPainter Painter(this);
|
|||
|
|
Painter.setRenderHint(QPainter::Antialiasing, true);
|
|||
|
|
|
|||
|
|
// 先画卡片主体。
|
|||
|
|
Painter.setPen(QPen(BorderColor, 1.0));
|
|||
|
|
Painter.setBrush(FillColor);
|
|||
|
|
Painter.drawRoundedRect(BodyRect, Radius, Radius);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} // namespace APP
|