Results 1 to 3 of 3

Thread: Is it possible to populate a list from a file so each entry has a checkbox?

  1. #1
    Join Date
    Jan 2015
    Posts
    8
    Qt products
    PyQt3 PyQt4
    Platforms
    Windows

    Default Is it possible to populate a list from a file so each entry has a checkbox?

    Hi,

    I'm using Python and trying to read in an xml file and populate a list QT ListWidget with some of its contents. Each entry should have a checkbox.

    In QT I created the list and added an item that has a checkbox by adding the item to the listWidget, then right clicking on it and selecting Edit Items > Properties > Set Flags to UserCheckable. So i can do it manually in QT.

    But when I read in the xml file to populate the ListWidget I can't make these items checkable.

    import xml.etree.ElementTree as et

    xml_file = os.path.join(path, testcase_file)
    tree = et.parse(xml_file)
    root = tree.getroot()

    for testcases in root.iter('testcase'):
    testcase_name = str(testcases.attrib)
    item = self.listWidgetTestCases
    item.addItem(QtGui.QApplication.translate("qadashb oard", testcase_name, None))
    # item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
    # item.setCheckState(QtCore.Qt.Unchecked)

    This creates a list of test case name in the ListWidget. However I can't add make these items into checkboxes. item.setFlags or ItemIsUserCheckable is not recognised for list Widgets, so the two lines are commented out in the above example.

    Any tips much appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to populate a list from a file so each entry has a checkbox?

    You set flags on items, not on the widget. QListWidgetItem::setFlags() certainly exists and works.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2015
    Posts
    8
    Qt products
    PyQt3 PyQt4
    Platforms
    Windows

    Default Re: Is it possible to populate a list from a file so each entry has a checkbox?

    Thanks, i achieved it with this:

    for testcases in root.iter('testcase'):
    testcase_name = QtGui.QApplication.translate(
    "qadashboard", str(testcases.attrib), None)
    item = QtGui.QListWidgetItem(testcase_name, self.listWidgetTestCases)
    item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
    item.setCheckState(QtCore.Qt.Unchecked)

Similar Threads

  1. A list box with an specific style checkbox
    By wxShayan in forum Newbie
    Replies: 1
    Last Post: 30th December 2012, 12:53
  2. Replies: 2
    Last Post: 23rd May 2011, 09:21
  3. Replies: 1
    Last Post: 21st April 2011, 14:20
  4. Help QT checkbox and text on list
    By jgaleanog in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2010, 14:40
  5. Drop down checkbox list
    By rbp in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2008, 01:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.