Qt在ListWidget中添加自定义ListItem对象 - sbw Blog

Qt在ListWidget中添加自定义ListItem对象

来源: 石博文博客 | 浏览: 25496 | 评论: 81 发表时间: 2014-03-04

Qt中的QListWidget可以实现一个列表,比如网页上经常出现的下拉列表框,其中一行就是一个ListItem,在添加时,常用的函数是QListWidget::addItem(QListWidgetItem * item),但这样只能添加QListWidgetItem这样的对象,如果想到像QQ等软件使用自定义的ListItem,一个简单的方法是自定义一个QWidget,然后使用QListWidget::setItemWidget(QListWidgetItem * item, QWidget * widget)来设置它的显示widget.



自定义一个widget

首先,自定义了一个QWidget,作为QListWidgetItem的子元素,所有的布局都在这个widget中完成,它便是后来显示的每个小条目.


添加自定义Item

首先,添加一个QListWidgetItem,然后为其设置Widget为我们自定义的Widget:


下面是在Linux上和Android的显示效果:

Qt在ListWidget中添加自定义ListItem对象
示例代码下载


  • 声明: 评论属于其发表者所有,不代表本站的观点和立场.
  • 塑料托板 回复该留言 时间: 2014-03-06

    不错 学习了

  • 路人甲 回复该留言 时间: 2014-12-25

    谢谢分享,找了好久才找到这个例子

  • bykege 回复该留言 时间: 2015-09-08

    ui->listWidget->setItemWidget(listItem1, custom1); 这句代码报错,显示无法从“const QString”转换为“QListWidgetItem

  • bykege 回复该留言 时间: 2015-09-09

    非常有用的帖子!!!感谢

  • 路人甲 回复该留言 时间: 2015-09-10

    listItem1 因该是QListWidgetItem类型的,你可能类型创建错误了

  • 路人甲 回复该留言 时间: 2015-10-13

    精简,直接,了得,非常好! 非常感谢! 本来一直想用QListView来着,没有找到自定义item的,后面找到这个,哈哈这个才是我要的!!![color: Red][/color]

  • 路人甲 回复该留言 时间: 2015-10-16

    问下,如果要动态修改咋办? 比如里面的第二项里面的 text2 我要修改成 你好 难道是先删除这一整个项,然后插入一个新的?

  • 石博文 回复该留言 时间: 2015-10-16

    修改你自定义的那个 widget 的数据就可以了呀

  • 路人甲 回复该留言 时间: 2016-02-11

    如何移除这个自定义控件呢?

  • 路人甲 回复该留言 时间: 2016-04-17

    直接 remove,QListWidget会帮你删除的,不过你在外面不能在持有对象的指针了,不然就。。。

  • 路人甲 回复该留言 时间: 2017-01-09

    博主 你好, 我在使用 QListWidget 的时候遇到一些问题: 首先我使用的是 mac 下的 qt 开发环境, 使用自定义的 item 时, 选中不会高亮了, itemEntered的判定区域也是不对的, 最主要的是 自定义的 widget 的效果(背景色效果)都无法显示出来. 请问一下, 这个是什么问题, 是QListWidget在 mac 环境下不支持的问题吗?

  • 路人甲 回复该留言 时间: 2017-12-20

    博主,我要怎么给列表添加第二项,按这个我添加了表单的一个小项目但是不能additem第二行

  • 路人甲 回复该留言 时间: 2022-04-12

    可以水平添加吗?

  • continua a leggere 回复该留言 时间: 2026-11-15

    Wonderful items from you, man. I have be aware your stuff previous to and you are just too fantastic. I actually like what you have received right here, really like what you are saying and the way in which by which you assert it. You're making it entertaining and you continue to care for to stay it wise. I cant wait to learn far more from you. That is really a great site.

  • Elmerhible 回复该留言 时间: 2026-11-15

    Главная <a href=https://bs2best3.com/>Bs2best категории</a>

  • Brianten 回复该留言 时间: 2026-11-15

    Check This Out https://peaksview.me/one-bedroom-chalet/

  • www.bipmessenger.com 回复该留言 时间: 2026-11-15

    Hey there! I just wanted to ask if you ever have any problems with hackers? My last blog posting sites for seo (<a href="https://www.bipmessenger.com">www.bipmessenger.com</a>) (wordpress) was hacked and I ended up losing many months of hard work due to no back up. Do you have any methods to protect against hackers?

  • consultant GEO Paris 回复该留言 时间: 2026-11-15

    https://consultant-seo-geo-paris.fr/ Hi there to every body, it's my first visit of this weblog; this blog carries amazing and in fact fine data in support of visitors.

  • AnthonyCet 回复该留言 时间: 2026-11-15

    узнать больше <a href=https://blsp.top>Sprut</a>

  • Brianten 回复该留言 时间: 2026-11-15

    check my blog https://peaksview.me/two-bedroom-forest-chalet/

  • GoelanceR.cOm 回复该留言 时间: 2026-11-15

    Hi there, after reading this remarkable post i am as well happy to share my experience here with colleagues. https://goelancer.com/question/lunettes-anti-lumiere-bleue-protegez-vos-yeux-des-ecrans-11/

  • AnthonyCet 回复该留言 时间: 2026-11-16

    посетить сайт <a href=https://blsp.top>blsp кристалл</a>

  • Michealbum 回复该留言 时间: 2026-11-16

    Следующая страница <a href=http://republic24.top/>ЛНР МЕФ</a>

  • AnthonyCet 回复该留言 时间: 2026-11-16

    веб-сайте <a href=https://blsp.top/>blsp вход</a>

  • yume-sma.com 回复该留言 时间: 2026-11-16

    Excellent goods from you, man. I have understand your stuff previous to and you are just extremely magnificent. I actually like what you have acquired here, certainly like what you're saying and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I can not wait to read far more from you. This is really a great site.

  • expert SEO Lille 回复该留言 时间: 2026-11-16

    https://consultant-seo-lille.fr/ Amazing blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog jump out. Please let me know where you got your design. Bless you

  • Brianten 回复该留言 时间: 2026-11-16

    anonymous https://peaksview.me/one-bedroom-chalet/

  • YourAnchorTexts 回复该留言 时间: 2026-11-16

    Fastidious response in return of this difficulty with real arguments and describing the whole thing on the topic of that. Also visit my site :: <a href="https://Rentry.co/13114-your-article-title">YourAnchorTexts</a>

  • Brianten 回复该留言 时间: 2026-11-16

    top article https://peaksview.me/two-bedroom-forest-chalet/

  • Michealbum 回复该留言 时间: 2026-11-16

    Перейти на сайт <a href=http://republic24.top>Луганск альфа</a>

  • webpage 回复该留言 时间: 2026-11-16

    I am really loving the theme/design of your weblog. Do you ever run into any browser compatibility issues? A small number of my blog audience have complained about my site not operating correctly in Explorer but looks great in Safari. Do you have any recommendations to help fix this issue?

  • MORE INFO 回复该留言 时间: 2026-11-16

    Way cool! Some very valid points! I appreciate you penning this post plus the rest of the website is extremely good.

  • tower rush 回复该留言 时间: 2026-11-16

    https://tower-rushes.fr/ When I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the same comment. Is there a means you are able to remove me from that service? Kudos!

  • Casino en ligne 回复该留言 时间: 2026-11-16

    Hey there, I think your blog might be having browser compatibility issues. When I look at your blog in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, awesome blog!

  • chicken road jeu 回复该留言 时间: 2026-11-16

    https://chickens-roads.fr/ Hi, I do believe this is a great site. I stumbledupon it ;) I will return yet again since I book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to help others.

  • flouz-casino.fr 回复该留言 时间: 2026-11-17

    https://flouz-casino.fr/ Thank you for sharing your info. I truly appreciate your efforts and I will be waiting for your further write ups thank you once again.

  • Corey 回复该留言 时间: 2026-11-17

    Its such as you read my mind! You appear to know so much approximately this, like you wrote the e book in it or something. I think that you simply could do with a few p.c. to power the message house a little bit, however instead of that, this is excellent blog. An excellent read. I'll definitely be back. Also visit my blog post; <a href="http://Mirotara.com/it/component/phocaguestbook/1">Corey</a>

  • EdmondJub 回复该留言 时间: 2026-11-17

    такой https://redmay.ru/

  • EdmondJub 回复该留言 时间: 2026-11-17

    нажмите, чтобы подробнее https://redmay.ru/

  • buy diazepam 回复该留言 时间: 2026-11-17

    Premier xxx platforms offer high-quality content for adult entertainment. Choose trusted platforms for a safe and enjoyable experience. Look at my page - <a href="https://datinganalyzer.com">buy diazepam</a>

  • Williameffit 回复该留言 时间: 2026-11-17

    this content https://hewstore.com

  • Williameffit 回复该留言 时间: 2026-11-17

    check my reference https://hewstore.com/

  • alfred investigation 回复该留言 时间: 2026-11-17

    Can I simply just say what a relief to find somebody who really knows what they're talking about online. You definitely know how to bring a problem to light and make it important. More people must check this out and understand this side of the story. I can't believe you aren't more popular because you most certainly possess the gift. https://goelancer.com/question/securite-en-magasin-a-ange-gardien-preparer-une-strategie-adaptee-6/

  • Manuelnib 回复该留言 时间: 2026-11-18

    сюда https://vodkabet-vodka10cyl.com/

  • Douglascip 回复该留言 时间: 2026-11-18

    этот сайт https://vodkabet-vodkakz.com

  • Douglascip 回复该留言 时间: 2026-11-18

    продолжить https://vodka-bet-vodka11cyl.com/

  • мимино 回复该留言 时间: 2026-11-18

    С технической точки зрения платформа использует SSL-шифрование 256-bit для защиты личной и финансовой информации пользователей — уровень защиты, сопоставимый с онлайн-банкингом.

  • Heim Studio 回复该留言 时间: 2026-11-18

    Завести учетную запись в Джет казино легко и быстро с любого гаджета.

  • Trentmes 回复该留言 时间: 2026-11-18

    другие https://vodka9cyl-vodkabet.com/

  • Trentmes 回复该留言 时间: 2026-11-18

    каталог https://vodka9cyl-vodkabet.com/

  • bbet eu 回复该留言 时间: 2026-11-18

    Ogni membro del team è uno specialista altamente formato con anni di esperienza nel settore.

  • 1xbet вход зеркало 回复该留言 时间: 2026-11-18

    Любители получили возможность играть в казино 1xbet на официальном сайте не сразу, так как изначально проект создавался для ставок на спорт.

  • MichaelLoulk 回复该留言 时间: 2026-11-19

    перейдите на этот сайт https://vodkabet-vodka10cyl.com/

  • lire le guide 回复该留言 时间: 2026-11-19

    https://www.auto-moto.com/casino-en-ligne I could not resist commenting. Perfectly written!

  • Darinwredo 回复该留言 时间: 2026-11-19

    this page https://bstash.net/

  • MichaelLoulk 回复该留言 时间: 2026-11-19

    здесь https://vodkabet-vodkakz.com/

  • Matthewtem 回复该留言 时间: 2026-11-19

    сюда https://vodkabet-vodka10cyl.com/

  • spadyTal 回复该留言 时间: 2026-11-19

    <a href="https://darkstore.bz/product/facebook-akkaunt-ssa-farm-3-dnej-progretyj-cookies-token?p=78104">Facebook аккаунты США | Фарм 3+ дней | Cookies + Token | Прогретые аккаунты</a>

  • Ralphhiess 回复该留言 时间: 2026-11-19

    sites https://bclub-shop.cc/

  • blowjob porn 回复该留言 时间: 2026-11-19

    Top adult platforms bieden premium inhoud voor volwassenen. Ontdek gegarandeerde adult sites voor kwaliteit en privacy. Also visit my homepage ... <a href="https://deepmarketsweb.com">blowjob porn</a>

  • casino en ligne 回复该留言 时间: 2026-11-19

    https://www.public.fr/meilleur-casino-en-ligne-france I think that is among the most vital info for me. And i am glad studying your article. But should commentary on few common issues, The web site taste is ideal, the articles is really excellent : D. Excellent process, cheers

  • website 回复该留言 时间: 2026-11-20

    Howdy! Do you use Twitter? I'd like to follow you if that would be okay. I'm absolutely enjoying your blog and look forward to new posts. http://fenjie888.com/comment/html/?44776.html

  • Samuelled 回复该留言 时间: 2026-11-20

    navigate to this site <a href=https://multiroblox.cc>multiroblox</a>

  • Samuelled 回复该留言 时间: 2026-11-20

    useful content <a href=https://multiroblox.cc/>how to run multiple roblox accounts</a>

  • MichaelGom 回复该留言 时间: 2026-11-21

    такой <a href=https://bsme.ac>Bs2web</a>

  • MichaelGom 回复该留言 时间: 2026-11-21

    Перейти на сайт <a href=https://bsme.ac/>bsme at вход</a>

  • buy xanax online 回复该留言 时间: 2026-11-21

    Content for adults can be streamed on trusted platforms for privacy. Explore secure video sources for quality viewing. my web site: <a href="https://zoloftrem.com">buy xanax online</a>

  • MichaelGom 回复该留言 时间: 2026-11-21

    интернет <a href=https://bsme.ac>Bs2web</a>

已有 68 位网友发表了一针见血的评论,你还等什么?
  • 昵称: *
  • 邮箱:
  • 网址:
  • 记住我的信息
  • Color
  • Red
  • Blue
  • Code
  • bash
  • cpp
  • css
  • java
  • js
  • perl
  • php
  • python
  • ruby
  • sql
  • xml