UASQuickViewItem.cc 1.43 KB
Newer Older
1 2
#include "UASQuickViewItem.h"
#include <QVBoxLayout>
3 4 5
#include <QStyleOption>
#include <QPainter>
#include <QSizePolicy>
6

7 8
UASQuickViewItem::UASQuickViewItem(QWidget *parent) :
    QWidget(parent)
9
{
10 11 12 13
    QVBoxLayout* layout = new QVBoxLayout();
    layout->setMargin(0);
    layout->setSizeConstraint(QLayout::SetMinimumSize);

14 15
    titleLabel = new QLabel(this);
    titleLabel->setAlignment(Qt::AlignHCenter);
16 17 18 19
    titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum);
    titleLabel->setObjectName(QString::fromUtf8("title"));
    layout->addWidget(titleLabel);

20 21
    valueLabel = new QLabel(this);
    valueLabel->setAlignment(Qt::AlignHCenter);
22 23 24 25 26 27 28
    valueLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum);
    valueLabel->setObjectName(QString::fromUtf8("value"));
    valueLabel->setText("0.00");
    layout->addWidget(valueLabel);

    layout->addSpacerItem(new QSpacerItem(20, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
    this->setLayout(layout);
29 30 31 32
}

void UASQuickViewItem::setValue(double value)
{
33
    valueLabel->setText(QString::number(value,'f',4));
34 35 36 37 38 39
}

void UASQuickViewItem::setTitle(QString title)
{
    titleLabel->setText(title);
}
40 41 42 43 44 45 46 47 48 49 50

/**
 * Implement paintEvent() so that stylesheets work for our custom widget.
 */
void UASQuickViewItem::paintEvent(QPaintEvent *)
 {
     QStyleOption opt;
     opt.init(this);
     QPainter p(this);
     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
 }