呃……反正这篇博客我是本不打算写的,这次的音乐播放器没什么大的变化,主要是在界面上稍微做了些改进,代码是照搬v1.0的,不过这次加了换肤(这个是班门弄斧了些哈),不过话说回来,也是自己辛辛苦苦自己组装的音乐播放器吧,没有窃取别人家的劳动成果,我感觉这个还算的上是一个让我欣慰的原因,一向是剃头挑子-一头热的我,不知道这次能坚持多久,只能说声走一步算一步了。甭废话了,放代码:

widget.h

#include"widget.h"

#include"ui_widget.h"
#include
Widget::Widget(QWidget*parent):
QWidget(parent),
ui(newUi::Widget)
{
ui->setupUi(this);
player=newQMediaPlayer(this);
list=newQMediaPlaylist;
QDirdir("E:/音乐");
foreach(QFileInfoinfo,dir.entryInfoList())
{
if(info.exists())
{
list->addMedia(QUrl(info.absoluteFilePath()));
ui->show->addItem(info.fileName());
}
}
ui->V->setRange(0,100);
list->setCurrentIndex(1);
player->setPlaylist(list);
player->setVolume(50);
connect(ui->V,SIGNAL(valueChanged(int)),player,SLOT(setVolume(int)));
intwidth=this->width();
QToolButton*minButton=newQToolButton(this);
QToolButton*closeButton=newQToolButton(this);
connect(closeButton,SIGNAL(clicked(bool)),this,SLOT(on_closeButton_clicked()));
connect(minButton,SIGNAL(clicked(bool)),this,SLOT(on_minButton_clicked()));
QPixmapminPix=style()->standardPixmap(QStyle::SP_TitleBarUnshadeButton);
QPixmapclosePix=style()->standardPixmap(QStyle::SP_TitleBarCloseButton);
minButton->setIcon(minPix);
closeButton->setIcon(closePix);
minButton->setGeometry(width-46,5,20,20);
closeButton->setGeometry(width-25,5,20,20);
minButton->setToolTip(tr("换肤"));
closeButton->setToolTip(tr("关闭"));
minButton->setStyleSheet("background-color:transparent;");
closeButton->setStyleSheet("background-color:transparent;");
ui->num->setText("已找到"+QString::number(ui->show->count(),10)+"首音乐");
player->setVolume(25);
ui->V->setValue(25);
ui->V->accessibleDescription();
connect(ui->V,SIGNAL(valueChanged(int)),player,SLOT(setVolume(int)));
connect(ui->show,SIGNAL(clicked(QModelIndex)),this,SLOT(toplay(QModelIndex)));
}
Widget::~Widget()
{
deleteui;
}
voidWidget::on_Prvious_clicked()
{
list->previous();
player->play();
ui->show->autoFillBackground();
}
voidWidget::on_Play_clicked()
{
if(ui->Play->text()=="播放")
{
player->play();
ui->Play->setText("暂停");
}
else
{
player->pause();
ui->Play->setText("播放");
}
}
voidWidget::on_Next_clicked()
{
list->next();
player->play();
}
voidWidget::mousePressEvent(QMouseEvent*event)
{
if(event->button()==Qt::LeftButton)
{
mouse_press=true;
move_point=event->pos();//鼠标相对于窗体的位置(或者使用event->globalPos()-this->pos())
}
}
voidWidget::mouseMoveEvent(QMouseEvent*event)
{
if(mouse_press)//若鼠标左键被按下
{
QPointmove_pos=event->globalPos();//鼠标相对于屏幕的位置
this->move(move_pos-move_point);//移动主窗体位置
}
}
voidWidget::mouseReleaseEvent(QMouseEvent*event)
{
mouse_press=false;//设置鼠标为未被按下
}
voidWidget::on_closeButton_clicked()
{
this->close();
}
voidWidget::on_minButton_clicked()
{
staticinti=0;
i++;
QPalettep;
QPixmap*map;
switch(i%4){
case0:
map=newQPixmap(":/picture/001.jpg");
break;
case1:
map=newQPixmap(":/picture/002.jpg");
break;
case2:
map=newQPixmap(":/picture/003.jpg");
break;
case3:
map=newQPixmap(":/picture/004.jpg");
break;
default:
break;
}
p.setBrush(QPalette::Window,QBrush(*map));
this->setPalette(p);
}
voidWidget::toplay(QModelIndexx)
{
list->setCurrentIndex(x.row());
player->play();

}

main.cpp

#include"widget.h"

#include
intmain(intargc,char*argv[])
{
QApplicationa(argc,argv);
Widgetw;
w.setWindowFlags(Qt::FramelessWindowHint);
w.setWindowTitle("MusicBox");
w.setAutoFillBackground(true);
QPalettep;
QPixmappixmap("E:/照片/壁纸/002.jpg");
p.setBrush(QPalette::Window,QBrush(pixmap));
w.setPalette(p);
QPixmappixmap1(":/picture/MP3.ico");
QIconpicture(pixmap1);
w.setWindowIcon(picture);
w.show();
returna.exec();

}

widget.h

#ifndefWIDGET_H

#defineWIDGET_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespaceUi{
classWidget;
}
classWidget:publicQWidget
{
Q_OBJECT
public:
explicitWidget(QWidget*parent=0);
voidmouseReleaseEvent(QMouseEvent*event);
voidmouseMoveEvent(QMouseEvent*event);
voidmousePressEvent(QMouseEvent*event);
~Widget();
privateslots:
voidtoplay(QModelIndexx);
voidon_Prvious_clicked();
voidon_Play_clicked();
voidon_Next_clicked();
voidon_minButton_clicked();
voidon_closeButton_clicked();
private:
Ui::Widget*ui;
QMediaPlayer*player;
QMediaPlaylist*list;
QPointmove_point;//移动的距离
boolmouse_press;//鼠标按下
};
#endif//WIDGET_H

Qt--音乐播放器 V2.0_vortex_新浪博客相关推荐

  1. [转载]Qt之解决中文乱码_vortex_新浪博客

    博主很给力 原文地址:Qt之解决中文乱码作者:一去二三里 在项目开发的过程中,中文乱码是比较常见的问题!用Qt开发也不例外,之前在做界面的时候没有发现什么问题,但是在程序移植的过程中问题出现了! 在W ...

  2. 计算机自带音乐怎么放,絮叨絮叨:如何在新浪博客上,放自己电脑里的音乐。...

    前言:(注意,情况正在起变化,解决方案请参见本文后记,本后记会不定时更新) 最近闲的没事也倒腾倒腾博客的各种功能,发现这个"音乐播放器"有诸多不便,很多歌曲它搜不到(比如大鼓.单弦 ...

  3. html代码 通用代码,新浪博客通用html代码及其使用方法

    经常上新浪博客又偶尔看到有些NX的博客总会把自己的领地打扮得漂漂亮亮的,总给人一种神圣敢,让人羡慕不已.其实方法很简单,你也可以轻松打造! 首先,你登陆你的博客 > 控制面板 > 首页内容 ...

  4. 普度网络营销策划_普度网络营销策划-齐宁_新浪博客

    标签: 杂谈 自媒体的盛行,让我们知道了文案的重要性.一条好的文案,可以让你的广告如虎添翼.一篇好的内容可以瞬间刷爆朋友圈.今天我要总结的就是如何做一个打动人内心心智的好文案. 文案最主要的目的是让消 ...

  5. [转载]Word直接发布新浪博客(以Word 2013为例)

    2019独角兽企业重金招聘Python工程师标准>>> 原文地址:Word直接发布新浪博客(以Word 2013为例) 作者:paulke2011 注意:这篇博客直接由Word 20 ...

  6. 关于幂律分布的一个笔记_哈克_新浪博客

    关于幂律分布的一个笔记_哈克_新浪博客 关于幂律分布的一个笔记     (2011-03-02 18:12:27)     转载▼     标签:     幂律     二八法则     杂谈     ...

  7. 新浪博客的视频如何下载

    新浪博客的视频如何下载 将新浪视频的播放网址年贴下面网址中的搜索栏,点击开始就能看到视频下载地址了.. http://www.flvcd.com/

  8. 火车头发布本地html,火车浏览器新浪博客自动调取本地文件发布脚本

    摸索了快一个星期了!终于磕磕巴巴弄出来一个新浪博客的自动发布脚本,附件共享在底部. 由于刚刚摸索,所以目前暂时验证码还是需要手动填写,貌似这个需要一个第三方的支持,说白了就是收费哒!火车浏览器脚本编辑 ...

  9. Action Golf 四个魔法球实战训练系列_huatuo_新浪博客

    Action & Golf 四个魔法球实战训练系列_huatuo_新浪博客

最新文章

  1. 轨迹规划概念总结——Dubins曲线
  2. Linux下安装Perl模块
  3. Android 8.0学习(31)---Android 8.0 中的 ART 功能改进
  4. 避免软件失败的7个关键实践——来自项目管理群的讨论
  5. android 查找所有dialog_android 布局文件layout分组的简单使用
  6. 真实VS虚拟,虚拟现实如何定义
  7. Python datetime 格式化字符串:strftime()
  8. tp3.2 配置相关说明
  9. 学习环境搭建:UDK2017 下载以及编译
  10. android离线天地图,天地图的移动App开发,离线地图下载不了
  11. W801单片机学习笔记——内部结构,总线架构篇
  12. css3实现图片360度旋转及animation、@keyframes的详解
  13. 1.深入理解C/C++中头文件(.h)与源文件(.c/.cpp)以及我们为什么需要.h头文件
  14. php从一个字符串中过滤掉英文,php过滤英文字符
  15. 计算机的文件打开记录怎么删,怎样删除最近使用的文档记录,电脑文档文件怎么删除...
  16. 【二 HLS】HLS接口的简单介绍
  17. 醇酰基转移酶基因对猕猴桃酯生物合成的作用
  18. 关于显著性检验,有你想要的!
  19. 熬夜肝了这一份C++开发详细学习路线
  20. TF Live 直播回放丨Frank Wu:当OpenStack遇到Tungsten Fabric

热门文章

  1. linux lids pdf,Linux入侵监测系统LIDS原理(3)
  2. java 私有静态类_java中,在私有的静态类中如何触发jbutton
  3. 有赞vant_vue+有赞vant的商品规格sku记录-小程序
  4. 高性能游戏本搭服务器,为吃鸡而生,这几款高性能游戏本不容错过!
  5. mysql数据备份数据解决方案_MYSQL数据备份解决方案
  6. 新浪微博php7升级实践,PHP7线上system time飙高问题
  7. 21天Jenkins打卡Day6安装插件
  8. 测试开发必备技能-Jmeter二次开发
  9. python3+telnetlib实现简单自动测试
  10. 怎么样把c语言和单片机融合,求助怎么把两个单片机c语言程序结合在一起?大一期末实验...