Qt-⽹易云⾳乐界⾯实现-5收藏列表,播放列表实现
QListWidgetQTableWidget
先上⽬前完成的内容吧,发现后⾯越写越多。在看看点击量,⼼凉凉。
完成了左侧的导航列表,还有就是右下⾓的播放列表。
//创建的歌单
my_Create_Music_List = new QListWidget(ui->widget_list);
connect(my_Create_Music_List,&QListWidget::itemClicked,this,&MainWindow::slot_my_Create_Music_List_itemClicked);
my_Create_Music_List->tStyleSheet("QListWidget{color:rgb(173,175,178); background:rgb(25,27,31);border:0px solid gray;}"
"QListWidget::Item{height:30px;border:0px solid gray;padding-left:15;}"
"QListWidget::Item:hover{color:rgb(255,255,255);background:transparent;border:0px solid gray;}"
"QListWidget::Item:lected{border-image:url(images/listwidget_h.png); color:rgb(255,255,255);border:0px solid gray;}" "QListWidget::Item:lected:active{background:#00FFFFFF;color:#FFFFFF;border-width:0;}");
//去掉滚动条
my_Create_Music_List->tVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
my_Create_Music_List->tHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
my_Create_Music_List->hide();
//创建列表测试
QListWidgetItem *add_item_10 = new QListWidgetItem(my_Create_Music_List);
add_item_10->tIcon(QIcon("./images/musicform/btn_like_n.png"));
add_item_10->tText("我喜欢的⾳乐");
QListWidgetItem *add_item_11 = new QListWidgetItem(my_Create_Music_List);
add_item_11->tIcon(QIcon("./images/lock.png"));
add_item_11->tText("我的⾳乐");
QListWidgetItem *add_item_12 = new QListWidgetItem(my_Create_Music_List);
add_item_12->tIcon(QIcon("./images/musiclist.png"));
add_item_12->tText("我创建的歌单1");
QListWidgetItem *add_item_13 = new QListWidgetItem(my_Create_Music_List);
add_item_13->tIcon(QIcon("./images/musiclist.png"));
add_item_13->tText("我创建的歌单2");
潜力行业QListWidgetItem *add_item_14 = new QListWidgetItem(my_Create_Music_List);
add_item_14->tIcon(QIcon("./images/musiclist.png"));
add_item_14->tText("我创建的歌单3");
//收藏的歌单
my_Collect_Music_List = new QListWidget(ui->widget_list);
connect(my_Collect_Music_List,&QListWidget::itemClicked,this,&MainWindow::slot_my_my_Collect_Music_List_itemClicked);
my_Collect_Music_List->tStyleSheet("QListWidget{color:rgb(173,175,178); background:rgb(25,27,31);border:0px solid gray;}"
"QListWidget::Item{height:30px;border:0px solid gray;padding-left:15;}"
"QListWidget::Item:hover{color:rgb(255,255,255);background:transparent;border:0px solid gray;}"
"QListWidget::Item:lected{border-image:url(images/listwidget_h.png); color:rgb(255,255,255);border:0px solid gray;}" "QListWidget::Item:lected:active{background:#00FFFFFF;color:#FFFFFF;border-width:0;}");
//去掉滚动条
my_Collect_Music_List->tVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
my_Collect_Music_List->tHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
my_Collect_Music_List->hide();
//收藏歌单测试
QListWidgetItem *add_item_15 = new QListWidgetItem(my_Collect_Music_List);
add_item_15->tIcon(QIcon("./images/musiclist.png"));
add_item_15->tText("我收藏的歌单1");
QListWidgetItem *add_item_16 = new QListWidgetItem(my_Collect_Music_List);
add_item_16->tIcon(QIcon("./images/musiclist.png"));
add_item_16->tText("我收藏的歌单2");
QListWidgetItem *add_item_17 = new QListWidgetItem(my_Collect_Music_List);
add_item_17->tIcon(QIcon("./images/musiclist.png"));
add_item_17->tText("我收藏的歌单3");
这⾥就是现在是⽤了4个listwidget ,需要再每个的触发函数中把其他三个的数据屏蔽了,不知道⽹易原⽣是不是这样实现的。
/*
* 推荐列表
摩羯双子
*/
void MainWindow::on_listWidget_itemClicked(QListWidgetItem *item)
{
Q_UNUSED(item);
// qDebug()<<item->text();
ui->listWidget_mymusic->clearSelection();
my_Collect_Music_List->clearSelection();
my_Create_Music_List->clearSelection();
}
/*
* 我的⾳乐列表
*/
void MainWindow::on_listWidget_mymusic_itemClicked(QListWidgetItem *item)方特二期
{
Q_UNUSED(item);
// qDebug()<<item->text();
ui->listWidget->clearSelection();
my_Collect_Music_List->clearSelection();
my_Create_Music_List->clearSelection();
}
/*
* 我创建的列表点击
*/
void MainWindow::slot_my_Create_Music_List_itemClicked(QListWidgetItem *item)
{
Q_UNUSED(item);
// qDebug()<<item->text();
ui->listWidget_mymusic->clearSelection();
ui->listWidget->clearSelection();
my_Collect_Music_List->clearSelection();
}
/*
* 我收藏的列表点击
*/
void MainWindow::slot_my_my_Collect_Music_List_itemClicked(QListWidgetItem *item)
{
Q_UNUSED(item);
// qDebug()<<item->text();
ui->listWidget_mymusic->clearSelection();
ui->listWidget->clearSelection();
my_Create_Music_List->clearSelection();
}
可以看下,这⾥就是间的把每个listwidget的最后⼀个选项取消。
还存在⼀个问题就是创建的歌单和收藏的歌单
这⾥就是⽤了简单的位置移动
/*
* 创建列表展开列表
*/
static bool unfold_Flag = fal;
void MainWindow::on_pushButton_unfold_clicked()
{
if(!unfold_Flag)
{
if(my_Create_Music_List->isHidden())
{
my_Create_Music_List->tGeometry(0,360,200,30*my_Create_Music_List->count()); my_Create_Music_List->show();
}
unfold_Flag = !unfold_Flag;
ui->pushButton_unfold->tStyleSheet("QPushButton{border-image:url(images/btn_down_n.png);}"
"QPushButton::hover{border-image:url(images/btn_down_h.png);}"
"QPushButton::presd{border-image:url(images/btn_down_n.png);}");
ui->widget_list->resize(200,ui->widget_list->height() + 30*my_Create_Music_List->count());
ui->widget_Collect_form->tGeometry(0,my_Create_Music_List->y()+30*my_Create_Music_List->count(),200,30); if(!my_Collect_Music_List->isHidden())
{
my_Collect_Music_List->tGeometry(0,ui->widget_Collect_form->y()+30,200,30*my_Collect_Music_List->count()); }
我渴望
}
el
{
my_Create_Music_List->hide();
unfold_Flag = !unfold_Flag;
ui->pushButton_unfold->tStyleSheet("QPushButton{border-image:url(images/btn_right_1_n.png);}"
"QPushButton::hover{border-image:url(images/btn_right_1_h.png);}"
"QPushButton::presd{border-image:url(images/btn_right_1_n.png);}");
ui->widget_list->resize(200,ui->widget_list->height() - 30*my_Create_Music_List->count());
ui->widget_Collect_form->tGeometry(0,370,200,30);
if(!my_Collect_Music_List->isHidden())
{
my_Collect_Music_List->tGeometry(0,ui->widget_Collect_form->y()+30,200,30*my_Collect_Music_List->count()); }
}
}
/*
* 收藏列表展开按钮
*/
static bool unfold_collect_Flag = fal;
qq诈骗
void MainWindow::on_pushButton_unfold_collect_clicked()
{
if(!unfold_collect_Flag)
{
if(my_Collect_Music_List->isHidden())
{
my_Collect_Music_List->tGeometry(0,ui->widget_Collect_form->y()+30,200,30*my_Collect_Music_List->count()); my_Collect_Music_List->show();
}
unfold_collect_Flag = !unfold_collect_Flag;
ui->pushButton_unfold_collect->tStyleSheet("QPushButton{border-image:url(images/btn_down_n.png);}"
"QPushButton::hover{border-image:url(images/btn_down_h.png);}"
"QPushButton::presd{border-image:url(images/btn_down_n.png);}");
升旗仪式心得体会
ui->widget_list->resize(200,ui->widget_list->height() + 30*my_Create_Music_List->count());
}
el
{
my_Collect_Music_List->hide();
unfold_collect_Flag = !unfold_collect_Flag;
ui->pushButton_unfold_collect->tStyleSheet("QPushButton{border-image:url(images/btn_right_1_n.png);}"
"QPushButton::hover{border-image:url(images/btn_right_1_h.png);}"
"QPushButton::presd{border-image:url(images/btn_right_1_n.png);}");
ui->widget_list->resize(200,ui->widget_list->height() - 30*my_Create_Music_List->count());
}
}
剩下的就是右侧的这个播放列表了,这个就是⽤了⼀个tabwidget来显⽰播放列表和历史记录
主要的还是qss的问题,这⾥还有很多细节没有实现,不过没有耐⼼了,暂时这样吧。
看下整个代码
#include "playlistform.h"
#include "ui_playlistform.h"
PlayListForm::PlayListForm(QWidget *parent) :
反抗期
QWidget(parent),腹泻怎么办
ui(new Ui::PlayListForm)
{
ui->tupUi(this);
ui->tabWidget->tTabText(0,"播放列表");
ui->tabWidget->tTabText(1,"历史记录");
ui->pushButton_PL_shoucang->tIcon(QIcon("./images/btn_shoucang_n.png"));
ui->pushButton_PL_delete->tIcon(QIcon("./images/btn_delete_n.png"));
ui->pushButton_PL_delete_2->tIcon(QIcon("./images/btn_delete_n.png"));
QHeaderView *headview = ui->tableWidget_playlist->verticalHeader(); //隐藏列
headview->tHidden(true);
headview = ui->tableWidget_playlist->horizontalHeader(); //隐藏⾏
headview->tHidden(true);
ui->tableWidget_playlist->tSelectionBehavior(QAbstractItemView::SelectRows); //选中整⾏
ui->tableWidget_playlist->tSelectionMode(QAbstractItemView::SingleSelection); //单⾏模式
ui->tableWidget_playlist->tColumnCount(4);
ui->tableWidget_playlist->tRowCount(20);
ui->tableWidget_playlist->tShowGrid(fal);
ui->tableWidget_playlist->tStyleSheet("QTableWidget{border-top:0px solid #e8f3f9;background:transparent;alternate-background-color:red;lection-backgro "QTableWidget::Item:lected:active{background:#00FFFFFF;color:#FFFFFF;border-width:0;}");
ui->tableWidget_playlist->horizontalHeader()->resizeSection(0,417);
ui->tableWidget_playlist->horizontalHeader()->resizeSection(1,50);
ui->tableWidget_playlist->horizontalHeader()->resizeSection(2,50);
ui->tableWidget_playlist->horizontalHeader()->resizeSection(3,50);
headview = ui->tableWidget_historylist->verticalHeader(); //隐藏列
headview->tHidden(true);
headview = ui->tableWidget_historylist->horizontalHeader(); //隐藏⾏
headview->tHidden(true);
ui->tableWidget_historylist->tSelectionBehavior(QAbstractItemView::SelectRows); //选中整⾏
ui->tableWidget_historylist->tSelectionMode(QAbstractItemView::SingleSelection); //单⾏模式
ui->tableWidget_historylist->tColumnCount(4);
ui->tableWidget_historylist->tRowCount(20);