开源一个list widget的项目界面,先看看效果
一、list widget其实list widget有很多种展示效果以上就是其实中一种
二、使用步骤 1.添加展示内容void SktChickForest::MxfInsertProductItem(
QListWidget *pListWdt,
const char *pstDesc,
const char *pstQuality,
const char *pstType,
const char *pstPic,
const char *pstVal)
{
CSktShowProduct *pUserItem = new CSktShowProduct(this);
SktShowItemContext(pUserItem, pstDesc, pstQuality, pstType, pstPic, pstVal);
QListWidgetItem *pWdtItem = new QListWidgetItem(pListWdt);
pWdtItem->setSizeHint(QSize(222, 335));
pListWdt->setItemWidget(pWdtItem, pUserItem);
pListWdt->setFlow(QListView::LeftToRight);
pListWdt->setResizeMode(QListView::Adjust);
int iCount = pListWdt->count();
pListWdt->insertItem(iCount, pWdtItem);
pListWdt->setViewMode(QListView::IconMode);
pListWdt->setStyleSheet(
"QListWidget{border:1px solid gray; color:black; }"
"QListWidget::Item{background:green; }"
"QListWidget::Item:hover{background:skyblue; }"
"QListWidget::item:selected{background:lightgray; color:red; }"
"QListWidget::item:selected:!active{border-width:0px; background:lightgreen; }"
);
}
MxfInsertProductItem(ui.productListWdt, "莫笑农家深山土鸡蛋", "等级:精品", "推荐:5星", ":/SktPicPath/egg/egg.png", "v1");
MxfInsertProductItem(ui.productListWdt, "莫笑农家精品当季大米", "等级:精品", "推荐:5星", ":/SktPicPath/egg/rice.png", "v2");
MxfInsertProductItem(ui.productListWdt, "莫笑农家深山散养大公鸡", "等级:精品", "推荐:5星", ":/SktPicPath/egg/chick.png", "v3");
2.获取选中选内容
void SktChickForest::SktShowProdList()
{
QListWidgetItem *pListWgtItem = ui.productListWdt->currentItem();
QWidget *pUserWdt = ui.productListWdt->itemWidget(pListWgtItem);
CSktShowProduct *pUserItem = static_cast(pUserWdt);
QString qsVal = pUserItem->ui.valLbl->text();
if (qsVal.isEmpty())
{
return;
}
}
connect(ui.productListWdt, SIGNAL(itemSelectionChanged()), this, SLOT(SktShowProdList()));
总结
本项目有好几个页面,等后续全部更新完成,就把源码分享出来,里面包括了监控,视频播放,还有聊天等一系列功能。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)