開發平台(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
這是我最後的結果
不知道還能不能有更好的寫法呢?
=========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) + "
%");
}