QCollator¶
The QCollator
class compares strings according to a localized collation algorithm. More…
New in version 5.2.
Synopsis¶
Functions¶
def
caseSensitivity
()def
compare
(s1, len1, s2, len2)def
compare
(s1, s2)def
compare
(s1, s2)def
ignorePunctuation
()def
locale
()def
numericMode
()def
operator()
(s1, s2)def
operator()
(s1, s2)def
setCaseSensitivity
(cs)def
setIgnorePunctuation
(on)def
setLocale
(locale)def
setNumericMode
(on)def
sortKey
(string)def
swap
(other)
Detailed Description¶
QCollator
is initialized with a QLocale
. It can then be used to compare and sort strings in using the ordering appropriate to the locale.
A QCollator
object can be used together with template-based sorting algorithms, such as std::sort(), to sort a list with QString
entries.
sortedStrings = QStringList(QStringList seq) order = QCollator() std::sort(seq.begin(), seq.end(), order) return seq
In addition to the locale, several optional flags can be set that influence the result of the collation.
Note
On Linux, Qt is normally compiled to use ICU. When it isn’t, all options are ignored and the only supported locales are the system default (that setlocale(LC_COLLATE, nullptr)
would report) and the “C” locale.
- class PySide6.QtCore.QCollator¶
PySide6.QtCore.QCollator(arg__1)
PySide6.QtCore.QCollator(locale)
- Parameters
locale –
PySide6.QtCore.QLocale
arg__1 –
PySide6.QtCore.QCollator
Constructs a QCollator
using the default locale’s collation locale.
The system locale, when used as default locale, may have a collation locale other than itself (e.g. on Unix, if LC_COLLATE is set differently to LANG in the environment). All other locales are their own collation locales.
See also
Constructs a QCollator
using the given locale
.
See also
- PySide6.QtCore.QCollator.caseSensitivity()¶
- Return type
Returns case sensitivity of the collator.
This defaults to case-sensitive until set.
Note
In the C locale, when case-sensitive, all lower-case letters sort after all upper-case letters, where most locales sort each lower-case letter either immediately before or immediately after its upper-case partner. Thus “Zap” sorts before “ape” in the C locale but after in most others.
See also
- PySide6.QtCore.QCollator.compare(s1, s2)¶
- Parameters
s1 –
QStringView
s2 –
QStringView
- Return type
int
Compares s1
with s2
.
Returns an integer less than, equal to, or greater than zero depending on whether s1
sorts before, with or after s2
.
- PySide6.QtCore.QCollator.compare(s1, len1, s2, len2)
- Parameters
s1 –
QChar
len1 – int
s2 –
QChar
len2 – int
- Return type
int
This is an overloaded function.
Compares s1
with s2
. len1
and len2
specify the lengths of the QChar
arrays pointed to by s1
and s2
.
Returns an integer less than, equal to, or greater than zero depending on whether s1
sorts before, with or after s2
.
- PySide6.QtCore.QCollator.compare(s1, s2)
- Parameters
s1 – str
s2 – str
- Return type
int
This is an overloaded function.
- PySide6.QtCore.QCollator.ignorePunctuation()¶
- Return type
bool
Returns whether punctuation and symbols are ignored when collating.
When true
, strings are compared as if all punctuation and symbols were removed from each string.
See also
- PySide6.QtCore.QCollator.locale()¶
- Return type
Returns the locale of the collator.
Unless supplied to the constructor or by calling setLocale()
, the system’s default collation locale is used.
See also
- PySide6.QtCore.QCollator.numericMode()¶
- Return type
bool
Returns true
if numeric sorting is enabled, false
otherwise.
When true
, numerals are recognized as numbers and sorted in arithmetic order; for example, 100 sortes after 99. When false
, numbers are sorted in lexical order, so that 100 sorts before 99 (because 1 is before 9). By default, this option is disabled.
See also
- PySide6.QtCore.QCollator.operator()(s1, s2)¶
- Parameters
s1 –
QStringView
s2 –
QStringView
- Return type
bool
A QCollator
can be used as the comparison function of a sorting algorithm. It returns true
if s1
sorts before s2
, otherwise false
.
See also
- PySide6.QtCore.QCollator.operator()(s1, s2)
- Parameters
s1 – str
s2 – str
- Return type
bool
This is an overloaded function.
- PySide6.QtCore.QCollator.setCaseSensitivity(cs)¶
- Parameters
cs –
CaseSensitivity
Sets the case-sensitivity of the collator to cs
.
See also
- PySide6.QtCore.QCollator.setIgnorePunctuation(on)¶
- Parameters
on – bool
Ignores punctuation and symbols if on
is true
, attends to them if false
.
See also
- PySide6.QtCore.QCollator.setLocale(locale)¶
- Parameters
locale –
PySide6.QtCore.QLocale
Sets the locale of the collator to locale
.
See also
- PySide6.QtCore.QCollator.setNumericMode(on)¶
- Parameters
on – bool
Enables numeric sorting mode when on
is true
.
See also
- PySide6.QtCore.QCollator.sortKey(string)¶
- Parameters
string – str
- Return type
Returns a for string
.
Creating the sort key is usually somewhat slower, than using the compare()
methods directly. But if the string is compared repeatedly (e.g. when sorting a whole list of strings), it’s usually faster to create the sort keys for each string and then sort using the keys.
Note
Not supported with the C (a.k.a. POSIX) locale on Darwin.
- PySide6.QtCore.QCollator.swap(other)¶
- Parameters
other –
PySide6.QtCore.QCollator
Swaps this collator with other
. This function is very fast and never fails.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.