kylin-nm/plugins/netconnect/deviceframe.cpp

49 lines
1.3 KiB
C++
Raw Permalink Normal View History

2022-06-02 16:27:45 +08:00
#include "deviceframe.h"
2022-06-14 14:37:49 +08:00
#include <QPainterPath>
#include <QPainter>
2022-06-02 16:27:45 +08:00
#define LAYOUT_MARGINS 18,0,24,0
#define FRAME_HEIGHT 58
#define RADIUS 6.0
DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
{
this->setFrameShape(QFrame::Box);
this->setFixedHeight(FRAME_HEIGHT);
QHBoxLayout *deviceLayout = new QHBoxLayout(this);
deviceLayout->setContentsMargins(LAYOUT_MARGINS);
setLayout(deviceLayout);
deviceLabel = new QLabel(this);
dropDownLabel = new DrownLabel(devName, this);
2022-06-17 18:48:59 +08:00
deviceSwitch = new KSwitchButton(this);
2022-06-02 16:27:45 +08:00
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
deviceLayout->addWidget(dropDownLabel);
deviceLayout->addWidget(deviceSwitch);
}
DeviceFrame::~DeviceFrame()
{
}
void DeviceFrame::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
path.addRoundedRect (rect, RADIUS, RADIUS);
QRect temp_rect(rect.left(), rect.top() + rect.height()/2, rect.width(), rect.height()/2);
path.addRect(temp_rect);
painter.drawPath(path);
QFrame::paintEvent(event);
}