2018-07-02 16:21:43 +08:00
|
|
|
#include "tipswidget.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
TipsWidget::TipsWidget(QWidget *parent) : QFrame(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TipsWidget::setText(const QString &text)
|
|
|
|
{
|
|
|
|
m_text = text;
|
|
|
|
|
|
|
|
setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height());
|
2018-07-18 11:12:46 +08:00
|
|
|
|
|
|
|
update();
|
2018-07-02 16:21:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TipsWidget::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
QFrame::paintEvent(event);
|
|
|
|
|
|
|
|
QPainter painter(this);
|
2019-09-26 21:11:39 +08:00
|
|
|
painter.setPen(QPen(palette().brightText(), 1));
|
2018-07-02 16:21:43 +08:00
|
|
|
|
|
|
|
QTextOption option;
|
|
|
|
option.setAlignment(Qt::AlignCenter);
|
|
|
|
painter.drawText(rect(), m_text, option);
|
|
|
|
}
|