C++/Qt实现网络音乐播放器(一)

功能需求

在Windows下设计一个音乐播放器 ,实现本地导入歌曲播放以及在线播放功能
开发工具:Qt5.9.1
外部库:ffmpeg-4.2-win32

界面样式效果设计

现在都是看脸时代,好看的界面布局和样式都是很重要的,奈何本人对这方面没啥天赋,所以仿照xx音乐的界面做了一个
主界面
在这里插入图片描述
播放列表界面
在这里插入图片描述
播放模式界面
在这里插入图片描述
主歌词界面
在这里插入图片描述
桌面歌词界面
在这里插入图片描述
按钮样式:
在这里插入图片描述
QPushButton {
font-size:20px;
color:#d8d800;
border-radius:22px;
border-width:3;
border-color:#d8d800;
border-style:solid;;
background-color:rgba(0,0,0,0);
}

QPushButton:hover { //当鼠标移动到按钮上空时的效果
font-size:20px;
color:#f9f900; //字体颜色
border-radius:22px; //设置圆形
border-width:3; //边框
border-color:#f9f900; //边框颜色
border-style:solid; //有边框
background-color:rgba(0,0,0,0); //背景完全透明 第四个值可以设置透明度列:50% 就是半透明
}
进度条样式:
QSlider::groove:horizontal,QSlider::add-page:horizontal{
height:3px;
border-radius:3px;
background:#636363;
}

QSlider::sub-page:horizontal{
height:8px;
border-radius:3px;
background:#ffaa00;
}

QSlider::handle:horizontal{
width:12px;
margin-top:-5px;
margin-bottom:-4px;
border-radius:6px;
background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.2 #ffffff,stop:0.8 #ffaa00);
}

界面无边框以及去掉自带退出并居中显示

   //去除自带关闭
    this->setWindowFlags(Qt::Tool | Qt::X11BypassWindowManagerHint);
    this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    //居中显示
    QDesktopWidget *desk=QApplication::desktop();
    int wd=desk->width();
    int ht=desk->height();
    this->move((wd-width())/2,(ht-height())/2);

最小化以及系统托盘

// 托盘
    trayIcon = new QSystemTrayIcon(QIcon(":/Image/logo.png"), this);
    trayIcon->setToolTip("芊芊音乐");
    // 创建菜单
    QMenu *menu = new QMenu;
    menu->addAction(QStringLiteral("退出"), qApp, SLOT(quit()));
    trayIcon->setContextMenu(menu);
    trayIcon->show();
    QObject::connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
    //退出
    QObject::connect(ui->m_pBtnQuit,SIGNAL(clicked(bool)),qApp,SLOT(quit()));

按钮互斥设置

  //设置互斥
    ui->m_pButMusicLibraryWget->setCheckable(true);
    ui->m_pButMusicMVWget->setCheckable(true);
    ui->m_pButDynamicWget->setCheckable(true);
    ui->m_pButListenListWget->setCheckable(true);
    ui->m_pButLocaMusicWget->setCheckable(true);
    ui->m_pButMusicDownLoadWget->setCheckable(true);
    ui->m_pButMySongListWget->setCheckable(true);
    ui->m_pButMyCollectionWget->setCheckable(true);
    m_pGrpMeun = new QButtonGroup(ui->Selectwidget);
    m_pGrpMeun->addButton(ui->m_pButMusicLibraryWget);
    m_pGrpMeun->addButton(ui->m_pButMusicMVWget);
    m_pGrpMeun->addButton(ui->m_pButDynamicWget);
    m_pGrpMeun->addButton(ui->m_pButListenListWget);
    m_pGrpMeun->addButton(ui->m_pButLocaMusicWget);
    m_pGrpMeun->addButton(ui->m_pButMusicDownLoadWget);
    m_pGrpMeun->addButton(ui->m_pButMySongListWget);
    m_pGrpMeun->addButton(ui->m_pButMyCollectionWget);
    m_pGrpMeun->setExclusive(true);

结论

写的不好勿怪,代码仅是学习使用请勿用作商业用途 后果自负
本地导入音乐并且播放 请看C++/Qt实现网络音乐播放器(二)
如果有问题可以添加上面图片里面的qq群

猜你喜欢

转载自blog.csdn.net/qq_34940879/article/details/103087452