77 lines
1.6 KiB
C++
77 lines
1.6 KiB
C++
|
|
/**
|
|||
|
|
* @file PaiWidget.cpp
|
|||
|
|
* @brief 带有边框的widget
|
|||
|
|
* @date 2013-01-29
|
|||
|
|
*/
|
|||
|
|
#include <QPainter>
|
|||
|
|
#include <QStyleOption>
|
|||
|
|
|
|||
|
|
#include "PaiWidget.h"
|
|||
|
|
|
|||
|
|
using namespace pai::gui;
|
|||
|
|
|
|||
|
|
PaiWidget::PaiWidget(QWidget *pParent, Qt::WindowFlags flags) :
|
|||
|
|
QWidget(pParent, flags),
|
|||
|
|
m_ShowTopBorder(true),
|
|||
|
|
m_ShowBottomBorder(true),
|
|||
|
|
m_ShowLeftBorder(true),
|
|||
|
|
m_ShowRightBorder(true)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
PaiWidget::~PaiWidget()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PaiWidget::ShowBorder(bool showTop, bool showBottom, bool showLeft, bool showRight)
|
|||
|
|
{
|
|||
|
|
m_ShowTopBorder = showTop;
|
|||
|
|
m_ShowBottomBorder = showBottom;
|
|||
|
|
m_ShowLeftBorder = showLeft;
|
|||
|
|
m_ShowRightBorder = showRight;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PaiWidget::SetBackgroundColor(const QColor & color)
|
|||
|
|
{
|
|||
|
|
m_BackgroundColor = color;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void PaiWidget::paintEvent(QPaintEvent *pEvent)
|
|||
|
|
{
|
|||
|
|
QWidget::paintEvent(pEvent);
|
|||
|
|
|
|||
|
|
// 此处用于绘制StyleSheet效果,如果PaiWidget作为Dialog的CentralWidget,不添加此句
|
|||
|
|
// StyleSheet将不起效。见defect 34430
|
|||
|
|
QStyleOption opt;
|
|||
|
|
opt.init(this);
|
|||
|
|
QPainter p(this);
|
|||
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|||
|
|
|
|||
|
|
QRect rt = rect();
|
|||
|
|
|
|||
|
|
QPainter painter(this);
|
|||
|
|
painter.setPen(QColor("#767F85"));
|
|||
|
|
|
|||
|
|
if(m_BackgroundColor.isValid())
|
|||
|
|
{
|
|||
|
|
painter.fillRect(rt, QBrush(m_BackgroundColor));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(m_ShowTopBorder)
|
|||
|
|
{
|
|||
|
|
painter.drawLine(rt.topLeft(), rt.topRight());
|
|||
|
|
}
|
|||
|
|
if(m_ShowBottomBorder)
|
|||
|
|
{
|
|||
|
|
painter.drawLine(rt.bottomLeft(), rt.bottomRight());
|
|||
|
|
}
|
|||
|
|
if(m_ShowLeftBorder)
|
|||
|
|
{
|
|||
|
|
painter.drawLine(rt.topLeft(), rt.bottomLeft());
|
|||
|
|
}
|
|||
|
|
if(m_ShowRightBorder)
|
|||
|
|
{
|
|||
|
|
painter.drawLine(rt.topRight(), rt.bottomRight());
|
|||
|
|
}
|
|||
|
|
}
|