推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
CBBing
V2EX  ›  Python

PyQt5 中 QListWidget 怎么获取 item 中 combox 的当前显示的值?

  •  
  •   CBBing · Apr 1, 2016 · 13375 views
    This topic created in 3884 days ago, the information mentioned may be changed or developed.
    在 QListWidget 中利用 QListWidgetItem 将每个 item 设置为一个 combox ,一共八个,怎样才能知道当前八个 combox 中的值
    Supplement 1  ·  Apr 2, 2016

    就像这个图片,我需要知道每个 combobox 里的值
    11 replies  •  2016-04-02 19:33:05 +08:00
    RqPS6rhmP3Nyn3Tm
    RqPS6rhmP3Nyn3Tm
    Apr 2, 2016 via Android❤️1
    1
    .value 试试
    CBBing
    CBBing
    OP
    Apr 2, 2016
    2
    @BXIA 不行,虽然不会报错,但还是得不到想要的值
    RqPS6rhmP3Nyn3Tm
    RqPS6rhmP3Nyn3Tm
    Apr 2, 2016 via Android❤️1
    3
    index = combo.findText(text, QtCore.Qt.MatchFixedString)
    if index >= 0:
    combo.setCurrentIndex(index)
    不知道你要表达的是不是这个意思
    CBBing
    CBBing
    OP
    Apr 2, 2016
    4
    @BXIA 不,我并不是想要改变 combo 里的值,而是需要知道它改变之后的值,因为想要它们每一个都不一样
    CBBing
    CBBing
    OP
    Apr 2, 2016
    5
    @BXIA 这是一个 QListWidget ,里面的 item 是通过 QListWidgetItem 添加的
    for i in range(8):
    item = QtWidgets.QListWidgetItem()
    item.setFont(font)
    combox=QtWidgets.QComboBox()
    combox.setFont(font_combox)
    combox.addItems(Port)
    combox.setCurrentIndex(i)
    self.listWidget.addItem(item)
    self.listWidget.setItemWidget(item,combox)
    RqPS6rhmP3Nyn3Tm
    RqPS6rhmP3Nyn3Tm
    Apr 2, 2016 via Android❤️1
    6
    抱歉,这个就不知道了…
    CBBing
    CBBing
    OP
    Apr 2, 2016
    7
    @BXIA 还是谢谢你,我在看文档,希望能找到解决方法
    CBBing
    CBBing
    OP
    Apr 2, 2016
    8
    @BXIA 我成功啦,谢谢你回复我
    CBBing
    CBBing
    OP
    Apr 2, 2016
    9
    @BXIA
    for i in range(8):
    combox=self.listWidget.itemWidget(self.listWidget.item(i))
    print(combox.currentText())
    RqPS6rhmP3Nyn3Tm
    RqPS6rhmP3Nyn3Tm
    Apr 2, 2016 via Android
    10
    原来是 currentText ,的确应该是这样
    难得看到一个用 PyQt5 的,不知道你用什么工具打包 standalone package?
    CBBing
    CBBing
    OP
    Apr 2, 2016
    11
    @BXIA 目前还没写完, IDE 用的 PyCharm ,这只是实验课的课程设计,之前只知道 Qt ,并没有学过,所以来 V2 问
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2139 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 14:02 · PVG 22:02 · LAX 06:02 · JFK 09:02
    ♥ Do have faith in what you're doing.