功能需求
在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羣