Updated:2021/12/03 山岸 Created:2021/07/01 山岸


Reference:

Tips:

主なFunction

ui = self.ui.llistWidget_category
ui.setSortingEnabled(True)
ui.setAlternatingRowColors(True)

Signals:

def currentItemChanged (current, previous)
def currentRowChanged (currentRow)
def currentTextChanged (currentText)
def itemActivated (item)
def itemChanged (item)
def itemClicked (item)
def itemDoubleClicked (item)
def itemEntered (item)
def itemPressed (item)
def itemSelectionChanged ()

Match Flags:

static Qt.MatchFlag	MatchCaseSensitive
          The search is case sensitive.
static Qt.MatchFlag	MatchContains
          The search term is contained in the item.
static Qt.MatchFlag	MatchEndsWith
          The search term matches the end of the item.
static Qt.MatchFlag	MatchExactly
          Performs QVariant-based matching.
static Qt.MatchFlag	MatchFixedString
          Performs string-based matching.
static Qt.MatchFlag	MatchRecursive
          Searches the entire hierarchy.
static Qt.MatchFlag	MatchRegExp
          Performs string-based matching using a regular expression as the search term.
static Qt.MatchFlag	MatchStartsWith
          The search term matches the start of the item.
static Qt.MatchFlag	MatchWildcard
          Performs string-based matching using a string with wildcards as the search term.
static Qt.MatchFlag	MatchWrap
          Perform a search that wraps around, so that when the search reaches the last item in the model, it begins again at the first item and continues until all items have been examined.

static Qt.MatchFlag MatchCaseSensitive(マッチケースセンシティブ
          大文字小文字を区別して検索します。
static Qt.MatchFlag MatchContains
          検索語が項目に含まれています。
static Qt.MatchFlag MatchEndsWith
          検索語が項目の末尾に一致します。
static Qt.MatchFlag MatchExactly
          QVariantベースのマッチングを行います。
static Qt.MatchFlag MatchFixedString
          文字列ベースのマッチングを行います。
static Qt.MatchFlag MatchRecursive
          階層全体を検索します。
static Qt.MatchFlag MatchRegExp
          検索語として正規表現を使用して、文字列ベースのマッチングを実行します。
static Qt.MatchFlag MatchStartsWith
          検索語がアイテムの先頭に一致します。
static Qt.MatchFlag MatchWildcard
          検索語にワイルドカードを含む文字列を使用して、文字列ベースのマッチングを実行します。
static Qt.MatchFlag MatchWrap
          検索がモデルの最後の項目に達したとき、最初の項目から再び開始し、すべての項目を調べるまで続けるように、回り込んだ検索を実行します。

Methods:

def addItem (item)
def addItem (label)
def addItems (labels)
def closePersistentEditor (item)
def count ()
def currentItem ()
def currentRow ()
def editItem (item)
def findItems (text, flags)
def indexFromItem (item)
def insertItem (row, item)
def insertItem (row, label)
def insertItems (row, labels)
def isSortingEnabled ()
def item (row)
def itemAt (p)
def itemAt (x, y)
def itemFromIndex (index)
def itemWidget (item)
def items (data)
def openPersistentEditor (item)
def removeItemWidget (item)
def row (item)
def selectedItems ()
def setCurrentItem (item)
def setCurrentItem (item, command)
def setCurrentRow (row)
def setCurrentRow (row, command)
def setItemWidget (item, widget)
def setSortingEnabled (enable)
def sortItems ([order=Qt.AscendingOrder])
def sortOrder ()
def takeItem (row)
def visualItemRect (item)

currentItemChanged 「ListWidgetの選択などが変わった」などの条件で使いやすい

Examples

全てのアイテムを取得

def get_all_items(self):
        return [self.list.item(index) for index in range(self.list.count())]

名前でアイテム選択

item = (listWidget.findItems(name, QtCore.Qt.MatchContains))[0]
if item.getName() == name:
    listWidget.setCurrentItem(item)

複数選択