开发平台(Platform): (Ex: Win10, Linux, ...)
vs 2015
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
qt
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
问题(Question):
我需要做一个仪表板
类似这样
https://www.microsoft.com/zh-tw/dynamics/crm-customer-center/Tile_buttons.PNG
我目前是自己写一个widget(widget.cpp)
然后在主ui(dashboard.cpp)把他塞进一个QFrame
这是我最后的结果 http://imgur.com/WupfSts
不知道还能不能有更好的写法呢?
=========dashboard.cpp=====
dashboard::dashboard(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
s1 = new QSlider(this);
s1->setGeometry(450, 150, 20, 100);
w1 = new Widget(ui.frame);
ui.frame->setStyleSheet("QFrame{border-image:url(Image/back.PNG)}");
w1 ->resize(400, 400);
connect(s1, SIGNAL(valueChanged(int)), w1, SLOT(setProgress(int)));
connect(s1, SIGNAL(valueChanged(int)), w2, SLOT(setProgress(int)));
}
=======widget.cpp=============
void Widget::paintEvent(QPaintEvent *)
{
QPainter p(this);
QPen pen;
pen.setWidth(10);
pen.setStyle(Qt::DotLine);
p.setPen(pen);
p.setRenderHint(QPainter::Antialiasing);
QRectF rectangle(5.0, 5.0, 200.0, 200.0);
int startAngle = 180 * 16;
int spanAngle = -progress * 360 * 8;
//qDebug() << "progress: " << progress;
p.drawArc(rectangle, startAngle, spanAngle);
p.drawText(rectangle, Qt::AlignCenter, QString::number(progress * 100) + "
%");
}