QlistWidget自定義item

原文地址:https://blog.csdn.net/q5512049/article/details/47036349

原文地址: https://blog.csdn.net/weixin_33699280/article/details/81109406?utm_source=blogxgwz5

東西不能知道拿來用,但可以借鑒效果

簡單版

    QListWidget *list=new QListWidget;
    QListWidgetItem *item=new QListWidgetItem(list,0); 
    
    item->setSizeHint(QSize(100,100));
    QWidget *w = new QWidget(list);
    QHBoxLayout *layout=new QHBoxLayout(w);
    QPushButton *pushButton=new QPushButton(w);
    QCheckBox *checkBox=new QCheckBox(w);
    layout->addWidget(checkBox);
    layout->addWidget(pushButton);
    w->setLayout(layout);
    w->show();
    list->setItemWidget(item,w);
    list->show();

復雜版

QWidget *widget = new QWidget(ui.listWidget);
 
//創(chuàng)建自定義的item
widget->setStyleSheet("background:transparent;");
 
QLabel *TypeLabel = new QLabel(widget);
QPixmap myPix(qexeFullPath + QStringLiteral("/../res/DataBase/Common/") + GetFileType(filename) + ".png");
TypeLabel->setFixedSize(62, 32);
TypeLabel->setPixmap(myPix);
TypeLabel->setScaledContents(true);
TypeLabel->setStyleSheet("QLabel{padding-left:15px;padding-right:15px;}");
 
QWidget *frontArea = new QWidget(widget);
frontArea->setFixedHeight(32);
 
QLabel *TextLabel = new QLabel(frontArea);
TextLabel->setText(filename);
 
QLabel *TotalCopyLabel = new QLabel(frontArea);
TotalCopyLabel->setText("0 KB/0 KB");
 
QWidget *backArea = new QWidget(widget);
backArea->setFixedSize(158, 32);
 
QProgressBar *ProgressBar = new QProgressBar(backArea);
ProgressBar->setTextVisible(false);
ProgressBar->setFixedHeight(12);
ProgressBar->setStyleSheet("QProgressBar{ border:none; background:rgb(230, 230, 230); border-radius:0px; text-align:center; color:gray }\
                        QProgressBar::chunk{ background:rgb(71, 137, 250); border-radius:0px; }");
 
QLabel *SpeedLabel = new QLabel(backArea);
SpeedLabel->setText("0 B/s");
 
QPushButton *OpenFolderButton = new QPushButton(widget);
OpenFolderButton->setToolTip(QStringLiteral("打開文件夾"));
OpenFolderButton->setFixedSize(82, 32);
QIcon icon3(qexeFullPath + QStringLiteral("/../res/DataBase/Common/文件夾.png"));
OpenFolderButton->setIcon(icon3);
OpenFolderButton->setIconSize(QSize(24, 24));
OpenFolderButton->setProperty("index", QString::number(currentIndex));
OpenFolderButton->setStyleSheet("QPushButton{ margin-left:25px;margin-right:25px;border:none; color:white; background:none; }QPushButton:hover{color:#FFFFFF; background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 255, 255, 0% ), stop:1 rgba(200, 200, 200, 60% )); }\
                                                            QPushButton:pressed{ color:white; background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 255, 255, 0% ), stop:1 rgba(200, 200, 200, 80% )); }");
connect(OpenFolderButton, SIGNAL(clicked()), this, SLOT(OpenFolder()));
 
QLabel *TipIconLabel = new QLabel(widget);
QPixmap myPix2(qexeFullPath + QStringLiteral("/../res/DataBase/Common/等待.png"));
TipIconLabel->setFixedSize(25, 20);
TipIconLabel->setPixmap(myPix2);
TipIconLabel->setScaledContents(true);
TipIconLabel->setStyleSheet("QLabel{padding-left:0px;padding-right:5px;}");
 
QLabel *TipTextLabel = new QLabel(widget);
TipTextLabel->setText(QStringLiteral("等待中"));
TipTextLabel->setStyleSheet("QLabel{padding-left:0px;padding-right:0px;}");
TipTextLabel->setFixedWidth(55);
 
QPushButton *CloseButton = new QPushButton(widget);
CloseButton->setToolTip(QStringLiteral("取消下載"));
CloseButton->setFixedSize(34, 24);
QIcon icon4(qexeFullPath + QStringLiteral("/../res/DataBase/Common/關閉.png"));
CloseButton->setIcon(icon4);
CloseButton->setIconSize(QSize(12, 12));
CloseButton->setProperty("index", QString::number(currentIndex));
CloseButton->setStyleSheet("QPushButton{ margin-left:0px;margin-right:10px;border:none; color:white; background:none; }QPushButton:hover{color:#FFFFFF; background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 255, 255, 0% ), stop:1 rgba(200, 200, 200, 60% )); }\
                        QPushButton:pressed{ color:white; background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 255, 255, 0% ), stop:1 rgba(200, 200, 200, 80% )); }");
connect(CloseButton, SIGNAL(clicked()), this, SLOT(HideItem()));
 
QVBoxLayout *verLayout = new QVBoxLayout;
verLayout->setContentsMargins(0, 0, 0, 0);
verLayout->setMargin(0);
verLayout->setSpacing(0);
verLayout->addWidget(TextLabel);
verLayout->addWidget(TotalCopyLabel);
frontArea->setLayout(verLayout);
 
QVBoxLayout *verLayout2 = new QVBoxLayout;
verLayout2->setContentsMargins(0, 0, 0, 0);
verLayout2->setMargin(0);
verLayout2->setSpacing(0);
verLayout2->addWidget(ProgressBar);
verLayout2->addWidget(SpeedLabel);
backArea->setLayout(verLayout2);
 
QHBoxLayout *horLayout = new QHBoxLayout;
horLayout->setContentsMargins(0, 0, 0, 0);
horLayout->setMargin(0);
horLayout->setSpacing(0);
horLayout->addWidget(TypeLabel);
horLayout->addWidget(frontArea);
horLayout->addWidget(backArea);
horLayout->addWidget(OpenFolderButton);
horLayout->addWidget(TipIconLabel);
horLayout->addWidget(TipTextLabel);
horLayout->addWidget(CloseButton);
widget->setLayout(horLayout);
 
//將widget作為列表的item
QListWidgetItem *ITEM = new QListWidgetItem();
QSize size = ITEM->sizeHint();
ITEM->setSizeHint(QSize(size.width(), 56));
ui.listWidget->addItem(ITEM);
widget->setSizeIncrement(size.width(), 56);
ui.listWidget->setItemWidget(ITEM, widget);

復雜版效果圖:


?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市葵孤,隨后出現(xiàn)的幾起案子遂庄,更是在濱河造成了極大的恐慌咙鞍,老刑警劉巖讼育,帶你破解...
    沈念sama閱讀 217,185評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件苍碟,死亡現(xiàn)場離奇詭異牺蹄,居然都是意外死亡忘伞,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,652評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來氓奈,“玉大人翘魄,你說我怎么就攤上這事∫蹋” “怎么了暑竟?”我有些...
    開封第一講書人閱讀 163,524評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長育勺。 經常有香客問我但荤,道長,這世上最難降的妖魔是什么涧至? 我笑而不...
    開封第一講書人閱讀 58,339評論 1 293
  • 正文 為了忘掉前任腹躁,我火速辦了婚禮,結果婚禮上南蓬,老公的妹妹穿的比我還像新娘纺非。我一直安慰自己,他們只是感情好赘方,可當我...
    茶點故事閱讀 67,387評論 6 391
  • 文/花漫 我一把揭開白布铐炫。 她就那樣靜靜地躺著,像睡著了一般蒜焊。 火紅的嫁衣襯著肌膚如雪倒信。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,287評論 1 301
  • 那天泳梆,我揣著相機與錄音鳖悠,去河邊找鬼。 笑死优妙,一個胖子當著我的面吹牛乘综,可吹牛的內容都是我干的。 我是一名探鬼主播套硼,決...
    沈念sama閱讀 40,130評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼卡辰,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了邪意?” 一聲冷哼從身側響起九妈,我...
    開封第一講書人閱讀 38,985評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎雾鬼,沒想到半個月后萌朱,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經...
    沈念sama閱讀 45,420評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡策菜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,617評論 3 334
  • 正文 我和宋清朗相戀三年晶疼,在試婚紗的時候發(fā)現(xiàn)自己被綠了酒贬。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,779評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡翠霍,死狀恐怖锭吨,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情寒匙,我是刑警寧澤零如,帶...
    沈念sama閱讀 35,477評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站蒋情,受9級特大地震影響埠况,放射性物質發(fā)生泄漏耸携。R本人自食惡果不足惜棵癣,卻給世界環(huán)境...
    茶點故事閱讀 41,088評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望夺衍。 院中可真熱鬧狈谊,春花似錦、人聲如沸沟沙。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,716評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽矛紫。三九已至赎瞎,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間颊咬,已是汗流浹背务甥。 一陣腳步聲響...
    開封第一講書人閱讀 32,857評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留喳篇,地道東北人敞临。 一個月前我還...
    沈念sama閱讀 47,876評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像麸澜,于是被迫代替她去往敵國和親挺尿。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,700評論 2 354

推薦閱讀更多精彩內容

  • 在此特此聲明:一下所有鏈接均來自互聯(lián)網炊邦,在此記錄下我的查閱學習歷程编矾,感謝各位原創(chuàng)作者的無私奉獻 ! 技術一點一點積...
    遠航的移動開發(fā)歷程閱讀 11,113評論 12 197
  • 本系列出于AWeiLoveAndroid的分享馁害,在此感謝洽沟,再結合自身經驗查漏補缺,完善答案蜗细。以成系統(tǒng)裆操。 Andro...
    濟公大將閱讀 1,825評論 2 10
  • 又是年底怒详,無論大企業(yè)小企業(yè)都開始為年會忙碌! 傳奇也算是資深年會策劃和主持了踪区,自打進入職場昆烁,年會的策劃和主持工作就...
    傅傳奇閱讀 401評論 0 1
  • 我加入 “007”行動了。 看到“007”缎岗,你是不是馬上就想到那部美國間諜大片《007》静尼,想到那個長著迷人的眼睛,...
    俞燕文閱讀 215評論 0 3
  • 今天下夜班早传泊,回家以后急忙洗漱睡覺鼠渺,因為還要輔導朵朵寫作業(yè),鞏固一下他所學的知識眷细,為明天考試做準備拦盹。訂好了...
    王若涵媽媽閱讀 128評論 0 0