欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Qt實(shí)現(xiàn)網(wǎng)易云音樂進(jìn)度條效果

 更新時(shí)間:2020年08月20日 09:46:02   作者:番茄炒蛋不要蛋  
這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)網(wǎng)易云音樂進(jìn)度條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Qt網(wǎng)易云音樂中的音樂進(jìn)度條是一個(gè)小小的難關(guān),今天在Android寫記錄步數(shù)進(jìn)度條中突然想到了它。移動(dòng)端和電腦端自定義寫界面模塊的方式大同小異,現(xiàn)在將其中的代碼放出,供大家點(diǎn)評(píng)參閱。代碼還是比較混亂,請(qǐng)各位大俠還是要多多包涵。

其中我把這個(gè)類打包出來,類的實(shí)現(xiàn)就是靠painevent來完成的。其中的兩個(gè)自定義信號(hào)是為了快進(jìn)快退而準(zhǔn)備的,它們的實(shí)現(xiàn)不在本類中,大小位置也是在外部類中實(shí)現(xiàn)。其中的一些位置參數(shù),大小參數(shù)屬于本身創(chuàng)作需要,如有迷惑,還望海涵。

代碼:

#ifndef DOWN_PROGRESSBARWIDGET_H
#define DOWN_PROGRESSBARWIDGET_H
 
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QPaintEvent>
#include <QPainter>
#include <QMouseEvent>
#include <QPalette>
#include <QTimer>
 
class down_progressbarWidget : public QWidget
{
  Q_OBJECT
public:
  QString s="0:0";
  QString t="0:0";
  explicit down_progressbarWidget(QWidget *parent = 0);
  void changPosition(qint64 xx);
private:
  int X=56;
  qint64 druntime;//總進(jìn)度
  qint64 positontime;//當(dāng)前進(jìn)度
  QLabel *liftLabel;//左時(shí)間顯示
  QLabel *rightLabel;//右邊時(shí)間顯示
  QTimer *timer3;//刷新
  void paintEvent(QPaintEvent* event);
  void mousePressEvent(QMouseEvent *event);
  void mouseMoveEvent(QMouseEvent *event);
signals:
  void changeX();//自定義一個(gè)信號(hào)
public slots:
  void updatepos();
};
 
#endif // DOWN_PROGRESSBARWIDGET_H

#include "down_progressbarwidget.h"
 
down_progressbarWidget::down_progressbarWidget(QWidget *parent) : QWidget(parent)
{
  QPalette pal;
  pal.setColor(QPalette::WindowText,QColor(255,255,255));
  QFont font("Courier",10);
  liftLabel=new QLabel(this);
  rightLabel=new QLabel(this);
  liftLabel->setAlignment(Qt::AlignCenter);
  rightLabel->setAlignment(Qt::AlignCenter);
  liftLabel->setGeometry(0,10,50,50);
  rightLabel->setGeometry(640,10,50,50);
  rightLabel->setFont(font);
  liftLabel->setFont(font);
  liftLabel->setPalette(pal);
  rightLabel->setPalette(pal);
  timer3=new QTimer(this);
  timer3->setInterval(1000);
  connect(timer3,SIGNAL(timeout()),this,SLOT(updatepos()));
}
void down_progressbarWidget::paintEvent(QPaintEvent *event)
{
  Q_UNUSED(event);
  QPainter painter(this);
  painter.setRenderHint(QPainter::SmoothPixmapTransform);
  painter.setRenderHint(QPainter::Antialiasing);
  QColor baseColor(0,20,20);
  QColor inColor(255,0,0);
  QColor outColor(255,255,255);
  painter.save();
  painter.setPen(Qt::NoPen);
  painter.setBrush(baseColor);
  QRectF rect=QRectF(55,32,580,6);
  painter.drawRoundedRect(rect,3,3);
  painter.restore();
  painter.save();
  painter.setPen(Qt::NoPen);
  painter.setBrush(inColor);
  QRectF playrect=QRectF(55,32,X-63,6);
  painter.drawRoundedRect(playrect,3,3);
  painter.restore();
  painter.setPen(Qt::NoPen);
  painter.setBrush(outColor);
  painter.drawEllipse(X-7,25,20,20);
  painter.restore();
  painter.save();
  painter.setPen(Qt::NoPen);
  painter.setBrush(inColor);
  painter.drawEllipse(X,32,6,6);
  painter.restore();
}
void down_progressbarWidget::mousePressEvent(QMouseEvent *event)
{
  if(event->pos().y()>30&&event->pos().y()<50)
  {
      int value;
      value=event->pos().x();
      if(value<55)
      {
        X=56;
      }
      else if(value>635)
      {
        X=620;
      }
      else
      {
        X=value;
      }
      if(X<=620)
      {
        emit changeX();
      }
      update();
      setCursor(Qt::PointingHandCursor);
  }
  else
  {
    event->ignore();
  }
}
void down_progressbarWidget::mouseMoveEvent(QMouseEvent *event)//可以進(jìn)行拖動(dòng)
{
    int value;
    value=event->pos().x();
    if(value<55)
    {
      X=56;
    }
    else if(value>635)
    {
      X=620;
    }
    else
    {
      X=event->pos().x();
    }
  
    emit changeX();//自定義了一個(gè)信號(hào)
    update();
    setCursor(Qt::PointingHandCursor);
}
/*
 * 外部使用一個(gè)定時(shí)器每隔1秒觸發(fā)這個(gè)程序進(jìn)行更新
*/
void down_progressbarWidget::updatepos()//顯示歌曲時(shí)間進(jìn)度
{
  float a;
  a=(float)positontime/(float)druntime;
  X=a*580+56;
  qint64 time=druntime;
  double secondDouble=time/1000;
  int minint=secondDouble/60;
  int secondint=secondDouble-minint*60;
  double secondtime1=positontime/1000;
  int minint1=secondtime1/60;
  int secondint1=secondtime1-minint1*60;
  t=QString("%0:%1").arg(QString::number(minint1),QString::number(secondint1));
  s=QString("%0:%1").arg(QString::number(minint),QString::number(secondint));
  rightLabel->setText(s);
  liftLabel->setText(t);
  update();
}
void down_progressbarWidget::changPosition(qint64 xx)//外部寫入當(dāng)前時(shí)間
{
  this->positontime=xx;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論