|  | Home · All Classes · Modules

# QChar Class Reference
[QtCore module]

The QChar class provides a 16-bit Unicode character. More...

### Types

- enum Category { NoCategory, Mark_NonSpacing, Mark_SpacingCombining, Mark_Enclosing, ..., Symbol_Other }
- enum CombiningClass { Combining_BelowLeftAttached, Combining_BelowAttached, Combining_BelowRightAttached, Combining_LeftAttached, ..., Combining_IotaSubscript }
- enum Decomposition { NoDecomposition, Canonical, Font, NoBreak, ..., Fraction }
- enum Direction { DirL, DirR, DirEN, DirES, ..., DirBN }
- enum Joining { OtherJoining, Dual, Right, Center }
- enum SpecialCharacter { Null, Nbsp, ReplacementCharacter, ObjectReplacementCharacter, ..., LineSeparator }
- enum UnicodeVersion { Unicode_Unassigned, Unicode_1_1, Unicode_2_0, Unicode_2_1_2, ..., Unicode_5_0 }

### Methods

- __init__ (self)
- __init__ (self, str c)
- __init__ (self, QLatin1Char ch)
- __init__ (self, str c, str r)
- __init__ (self, int rc)
- __init__ (self, SpecialCharacter s)
- __init__ (self, QChar)
- Category category (self)
- str cell (self)
- str combiningClass (self)
- QString decomposition (self)
- Decomposition decompositionTag (self)
- int digitValue (self)
- Direction direction (self)
- bool hasMirrored (self)
- bool isDigit (self)
- bool isHighSurrogate (self)
- bool isLetter (self)
- bool isLetterOrNumber (self)
- bool isLower (self)
- bool isLowSurrogate (self)
- bool isMark (self)
- bool isNull (self)
- bool isNumber (self)
- bool isPrint (self)
- bool isPunct (self)
- bool isSpace (self)
- bool isSymbol (self)
- bool isTitleCase (self)
- bool isUpper (self)
- Joining joining (self)
- QChar mirroredChar (self)
- str row (self)
- setCell (self, str acell)
- setRow (self, str arow)
- str toAscii (self)
- QChar toCaseFolded (self)
- str toLatin1 (self)
- QChar toLower (self)
- QChar toTitleCase (self)
- QChar toUpper (self)
- int unicode (self)
- UnicodeVersion unicodeVersion (self)

### Static Methods

- Category category (int ucs4)
- str combiningClass (int ucs4)
- UnicodeVersion currentUnicodeVersion ()
- QString decomposition (int ucs4)
- Decomposition decompositionTag (int ucs4)
- int digitValue (int ucs4)
- Direction direction (int ucs4)
- QChar fromAscii (str c)
- QChar fromLatin1 (str c)
- int highSurrogate (int ucs4)
- bool isHighSurrogate (int ucs4)
- bool isLowSurrogate (int ucs4)
- Joining joining (int ucs4)
- int lowSurrogate (int ucs4)
- int mirroredChar (int ucs4)
- bool requiresSurrogates (int ucs4)
- int surrogateToUcs4 (int high, int low)
- int surrogateToUcs4 (QChar high, QChar low)
- int toCaseFolded (int ucs4)
- int toLower (int ucs4)
- int toTitleCase (int ucs4)
- int toUpper (int ucs4)
- UnicodeVersion unicodeVersion (int ucs4)

### Special Methods

- QString __add__ (self, QString s2)
- bool __eq__ (self, QChar c2)
- bool __ge__ (self, QChar c2)
- bool __gt__ (self, QChar c2)
- int __hash__ (self)
- bool __le__ (self, QChar c2)
- bool __lt__ (self, QChar c2)
- bool __ne__ (self, QChar c2)
- str __repr__ (self)
- str __str__ (self)
- unicode __unicode__ (self)

## Detailed Description

This class can be pickled.

The QChar class provides a 16-bit Unicode character.

In Qt, Unicode characters are 16-bit entities without any markup or structure. This class represents such an entity. It is lightweight, so it can be used everywhere. Most compilers treat it like a `unsigned short`.

QChar provides a full complement of testing/classification functions, converting to and from other formats, converting from composed to decomposed Unicode, and trying to compare and case-convert if you ask it to.

The classification functions include functions like those in the standard C++ header <cctype> (formerly <ctype.h>), but operating on the full range of Unicode characters. They all return true if the character is a certain type of character; otherwise they return false. These classification functions are isNull() (returns true if the character is '\0'), isPrint() (true if the character is any sort of printable character, including whitespace), isPunct() (any sort of punctation), isMark() (Unicode Mark), isLetter() (a letter), isNumber() (any sort of numeric character, not just 0-9), isLetterOrNumber(), and isDigit() (decimal digits). All of these are wrappers around category() which return the Unicode-defined category of each character.

QChar also provides direction(), which indicates the "natural" writing direction of this character. The joining() function indicates how the character joins with its neighbors (needed mostly for Arabic) and finally hasMirrored(), which indicates whether the character needs to be mirrored when it is printed in its "unnatural" writing direction.

Composed Unicode characters (like å) can be converted to decomposed Unicode ("a" followed by "ring above") by using decomposition().

In Unicode, comparison is not necessarily possible and case conversion is very difficult at best. Unicode, covering the "entire" world, also includes most of the world's case and sorting problems. operator==() and friends will do comparison based purely on the numeric Unicode value (code point) of the characters, and toUpper() and toLower() will do case changes when the character has a well-defined uppercase/lowercase equivalent. For locale-dependent comparisons, use QString.localeAwareCompare().

The conversion functions include unicode() (to a scalar), toLatin1() (to scalar, but converts all non-Latin-1 characters to 0), row() (gives the Unicode row), cell() (gives the Unicode cell), digitValue() (gives the integer value of any of the numerous digit characters), and a host of constructors.

QChar provides constructors and cast operators that make it easy to convert to and from traditional 8-bit `char`s. If you defined `QT_NO_CAST_FROM_ASCII` and `QT_NO_CAST_TO_ASCII`, as explained in the QString documentation, you will need to explicitly call fromAscii() or fromLatin1(), or use QLatin1Char, to construct a QChar from an 8-bit `char`, and you will need to call toAscii() or toLatin1() to get the 8-bit value back.

## Type Documentation

### QChar.Category

This enum maps the Unicode character categories.

The following characters are normative in Unicode:

Constant | Value | Description
--- | --- | ---
`QChar.Mark_NonSpacing` | `1` | Unicode class name Mn
`QChar.Mark_SpacingCombining` | `2` | Unicode class name Mc
`QChar.Mark_Enclosing` | `3` | Unicode class name Me
`QChar.Number_DecimalDigit` | `4` | Unicode class name Nd
`QChar.Number_Letter` | `5` | Unicode class name Nl
`QChar.Number_Other` | `6` | Unicode class name No
`QChar.Separator_Space` | `7` | Unicode class name Zs
`QChar.Separator_Line` | `8` | Unicode class name Zl
`QChar.Separator_Paragraph` | `9` | Unicode class name Zp
`QChar.Other_Control` | `10` | Unicode class name Cc
`QChar.Other_Format` | `11` | Unicode class name Cf
`QChar.Other_Surrogate` | `12` | Unicode class name Cs
`QChar.Other_PrivateUse` | `13` | Unicode class name Co
`QChar.Other_NotAssigned` | `14` | Unicode class name Cn

The following categories are informative in Unicode:

Constant | Value | Description
--- | --- | ---
`QChar.Letter_Uppercase` | `15` | Unicode class name Lu
`QChar.Letter_Lowercase` | `16` | Unicode class name Ll
`QChar.Letter_Titlecase` | `17` | Unicode class name Lt
`QChar.Letter_Modifier` | `18` | Unicode class name Lm
`QChar.Letter_Other` | `19` | Unicode class name Lo
`QChar.Punctuation_Connector` | `20` | Unicode class name Pc
`QChar.Punctuation_Dash` | `21` | Unicode class name Pd
`QChar.Punctuation_Open` | `22` | Unicode class name Ps
`QChar.Punctuation_Close` | `23` | Unicode class name Pe
`QChar.Punctuation_InitialQuote` | `24` | Unicode class name Pi
`QChar.Punctuation_FinalQuote` | `25` | Unicode class name Pf
`QChar.Punctuation_Other` | `26` | Unicode class name Po
`QChar.Symbol_Math` | `27` | Unicode class name Sm
`QChar.Symbol_Currency` | `28` | Unicode class name Sc
`QChar.Symbol_Modifier` | `29` | Unicode class name Sk
`QChar.Symbol_Other` | `30` | Unicode class name So
`QChar.NoCategory` | `0` | Qt cannot find an appropriate category for the character.

See also category().

### QChar.CombiningClass

### QChar.Decomposition

This enum type defines the Unicode decomposition attributes. See the Unicode Standard for a description of the values.

Constant | Value
--- | ---
`QChar.NoDecomposition` | `0`
`QChar.Canonical` | `1`
`QChar.Circle` | `8`
`QChar.Compat` | `16`
`QChar.Final` | `6`
`QChar.Font` | `2`
`QChar.Fraction` | `17`
`QChar.Initial` | `4`
`QChar.Isolated` | `7`
`QChar.Medial` | `5`
`QChar.Narrow` | `13`
`QChar.NoBreak` | `3`
`QChar.Small` | `14`
`QChar.Square` | `15`
`QChar.Sub` | `10`
`QChar.Super` | `9`
`QChar.Vertical` | `11`
`QChar.Wide` | `12`

See also decomposition().

### QChar.Direction

This enum type defines the Unicode direction attributes. See the Unicode Standard for a description of the values.

In order to conform to C/C++ naming conventions "Dir" is prepended to the codes used in the Unicode Standard.

Constant | Value
--- | ---
`QChar.DirAL` | `13`
`QChar.DirAN` | `5`
`QChar.DirB` | `7`
`QChar.DirBN` | `18`
`QChar.DirCS` | `6`
`QChar.DirEN` | `2`
`QChar.DirES` | `3`
`QChar.DirET` | `4`
`QChar.DirL` | `0`
`QChar.DirLRE` | `11`
`QChar.DirLRO` | `12`
`QChar.DirNSM` | `17`
`QChar.DirON` | `10`
`QChar.DirPDF` | `16`
`QChar.DirR` | `1`
`QChar.DirRLE` | `14`
`QChar.DirRLO` | `15`
`QChar.DirS` | `8`
`QChar.DirWS` | `9`

See also direction().

### QChar.Joining

This enum type defines the Unicode joining attributes. See the Unicode Standard for a description of the values.

Constant | Value
--- | ---
`QChar.Center` | `3`
`QChar.Dual` | `1`
`QChar.OtherJoining` | `0`
`QChar.Right` | `2`

See also joining().

### QChar.SpecialCharacter

Constant | Value | Description
--- | --- | ---
`QChar.Null` | `0x0000` | A QChar with this value isNull().
`QChar.Nbsp` | `0x00a0` | Non-breaking space.
`QChar.ReplacementCharacter` | `0xfffd` | The character shown when a font has no glyph for a certain codepoint. A special question mark character is often used. Codecs use this codepoint when input data cannot be represented in Unicode.
`QChar.ObjectReplacementCharacter` | `0xfffc` | Used to represent an object such as an image when such objects cannot be presented.
`QChar.ByteOrderMark` | `0xfeff` |
`QChar.ByteOrderSwapped` | `0xfffe` |
`QChar.ParagraphSeparator` | `0x2029` |
`QChar.LineSeparator` | `0x2028` |

### QChar.UnicodeVersion

Specifies which version of the Unicode standard introduced a certain character.

Constant | Value | Description
--- | --- | ---
`QChar.Unicode_1_1` | `1` | Version 1.1
`QChar.Unicode_2_0` | `2` | Version 2.0
`QChar.Unicode_2_1_2` | `3` | Version 2.1.2
`QChar.Unicode_3_0` | `4` | Version 3.0
`QChar.Unicode_3_1` | `5` | Version 3.1
`QChar.Unicode_3_2` | `6` | Version 3.2
`QChar.Unicode_4_0` | `7` | Version 4.0
`QChar.Unicode_4_1` | `8` | Version 4.1
`QChar.Unicode_5_0` | `9` | Version 5.0
`QChar.Unicode_Unassigned` | `0` | The value is not assigned to any character in version 5.0 of Unicode.

See also unicodeVersion().

## Method Documentation

### QChar.__init__ (self)

Constructs a null QChar ('\0').

See also isNull().

### QChar.__init__ (self, str c)

Constructs a QChar corresponding to ASCII/Latin-1 character ch.

### QChar.__init__ (self, QLatin1Char ch)

Constructs a QChar corresponding to ASCII/Latin-1 character ch.

### QChar.__init__ (self, str c, str r)

Constructs a QChar corresponding to ASCII/Latin-1 character ch.

### QChar.__init__ (self, int rc)

Constructs a QChar for Unicode cell cell in row row.

See also cell() and row().

### QChar.__init__ (self, SpecialCharacter s)

Constructs a QChar for the character with Unicode code point code.

### QChar.__init__ (self, QChar)

Constructs a QChar for the character with Unicode code point code.

### Category QChar.category (self)

Returns the character's category.

### Category QChar.category (int ucs4)

This is an overloaded function.

Returns the category of the UCS-4-encoded character specified by ucs4.

This function was introduced in Qt 4.3.

### str QChar.cell (self)

Returns the cell (least significant byte) of the Unicode character.

See also row().

### str QChar.combiningClass (self)

Returns the combining class for the character as defined in the Unicode standard. This is mainly useful as a positioning hint for marks attached to a base character.

The Qt text rendering engine uses this information to correctly position non-spacing marks around a base character.

### str QChar.combiningClass (int ucs4)

This is an overloaded function.

Returns the combining class for the UCS-4-encoded character specified by ucs4, as defined in the Unicode standard.

### UnicodeVersion QChar.currentUnicodeVersion ()

Returns the most recent supported Unicode version.

This function was introduced in Qt 4.8.

### QString QChar.decomposition (self)

Decomposes a character into its parts. Returns an empty string if no decomposition exists.

### QString QChar.decomposition (int ucs4)

This is an overloaded function.

Decomposes the UCS-4-encoded character specified by ucs4 into its constituent parts. Returns an empty string if no decomposition exists.

### Decomposition QChar.decompositionTag (self)

Returns the tag defining the composition of the character. Returns QChar.Single if no decomposition exists.

### Decomposition QChar.decompositionTag (int ucs4)

This is an overloaded function.

Returns the tag defining the composition of the UCS-4-encoded character specified by ucs4. Returns QChar.Single if no decomposition exists.

### int QChar.digitValue (self)

Returns the numeric value of the digit, or -1 if the character is not a digit.

### int QChar.digitValue (int ucs4)

This is an overloaded function.

Returns the numeric value of the digit, specified by the UCS-2-encoded character, ucs2, or -1 if the character is not a digit.

### Direction QChar.direction (self)

Returns the character's direction.

### Direction QChar.direction (int ucs4)

This is an overloaded function.

Returns the direction of the UCS-4-encoded character specified by ucs4.

### QChar QChar.fromAscii (str c)

Converts the ASCII character c to its equivalent QChar. This is mainly useful for non-internationalized software.

An alternative is to use QLatin1Char.

See also fromLatin1(), unicode(), and QTextCodec.codecForCStrings().

### QChar QChar.fromLatin1 (str c)

Converts the Latin-1 character c to its equivalent QChar. This is mainly useful for non-internationalized software.

See also fromAscii(), unicode(), and QTextCodec.codecForCStrings().

### bool QChar.hasMirrored (self)

Returns true if the character should be reversed if the text direction is reversed; otherwise returns false.

Same as (ch.mirroredChar() != ch).

See also mirroredChar().

### int QChar.highSurrogate (int ucs4)

Returns the high surrogate value of a ucs4 code point. The returned result is undefined if ucs4 is smaller than 0x10000.

### bool QChar.isDigit (self)

Returns true if the character is a decimal digit (Number_DecimalDigit); otherwise returns false.

### bool QChar.isHighSurrogate (self)

Returns true if the QChar is the high part of a utf16 surrogate (ie. if its code point is between 0xd800 and 0xdbff, inclusive).

### bool QChar.isHighSurrogate (int ucs4)

Returns true if the UCS-4-encoded character specified by ucs4 is the high part of a utf16 surrogate (ie. if its code point is between 0xd800 and 0xdbff, inclusive).

This function was introduced in Qt 4.7.

### bool QChar.isLetter (self)

Returns true if the character is a letter (Letter_* categories); otherwise returns false.

### bool QChar.isLetterOrNumber (self)

Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise returns false.

### bool QChar.isLower (self)

Returns true if the character is a lowercase letter, i.e. category() is Letter_Lowercase.

See also isUpper(), toLower(), and toUpper().

### bool QChar.isLowSurrogate (self)

Returns true if the QChar is the low part of a utf16 surrogate (ie. if its code point is between 0xdc00 and 0xdfff, inclusive).

### bool QChar.isLowSurrogate (int ucs4)

Returns true if the UCS-4-encoded character specified by ucs4 is the low part of a utf16 surrogate (ie. if its code point is between 0xdc00 and 0xdfff, inclusive).

This function was introduced in Qt 4.7.

### bool QChar.isMark (self)

Returns true if the character is a mark (Mark_* categories); otherwise returns false.

See QChar.Category for more information regarding marks.

### bool QChar.isNull (self)

Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false.

### bool QChar.isNumber (self)

Returns true if the character is a number (Number_* categories, not just 0-9); otherwise returns false.

See also isDigit().

### bool QChar.isPrint (self)

Returns true if the character is a printable character; otherwise returns false. This is any character not of category Cc or Cn.

Note that this gives no indication of whether the character is available in a particular font.

### bool QChar.isPunct (self)

Returns true if the character is a punctuation mark (Punctuation_* categories); otherwise returns false.

### bool QChar.isSpace (self)

Returns true if the character is a separator character (Separator_* categories); otherwise returns false.

### bool QChar.isSymbol (self)

Returns true if the character is a symbol (Symbol_* categories); otherwise returns false.

### bool QChar.isTitleCase (self)

Returns true if the character is a titlecase letter, i.e. category() is Letter_Titlecase.

This function was introduced in Qt 4.3.

See also isLower(), toUpper(), toLower(), and toTitleCase().

### bool QChar.isUpper (self)

Returns true if the character is an uppercase letter, i.e. category() is Letter_Uppercase.

See also isLower(), toUpper(), and toLower().

### Joining QChar.joining (self)

Returns information about the joining properties of the character (needed for certain languages such as Arabic).

### Joining QChar.joining (int ucs4)

This is an overloaded function.

Returns information about the joining properties of the UCS-4-encoded character specified by ucs4 (needed for certain languages such as Arabic).

### int QChar.lowSurrogate (int ucs4)

Returns the low surrogate value of a ucs4 code point. The returned result is undefined if ucs4 is smaller than 0x10000.

### QChar QChar.mirroredChar (self)

Returns the mirrored character if this character is a mirrored character; otherwise returns the character itself.

See also hasMirrored().

### int QChar.mirroredChar (int ucs4)

This is an overloaded function.

Returns the mirrored character if the UCS-4-encoded character specified by ucs4 is a mirrored character; otherwise returns the character itself.

See also hasMirrored().

### bool QChar.requiresSurrogates (int ucs4)

Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low parts of a utf16 surrogate (ie. if its code point is greater than or equals to 0x10000).

This function was introduced in Qt 4.7.

### str QChar.row (self)

Returns the row (most significant byte) of the Unicode character.

See also cell().

### QChar.setCell (self, str acell)

### QChar.setRow (self, str arow)

### int QChar.surrogateToUcs4 (int high, int low)

Converts a UTF16 surrogate pair with the given high and low values to its UCS-4 code point.

### int QChar.surrogateToUcs4 (QChar high, QChar low)

Converts a utf16 surrogate pair (high, low) to its ucs4 code point.

### str QChar.toAscii (self)

Returns the character value of the QChar obtained using the current codec used to read C strings, or 0 if the character is not representable using this codec. The default codec handles Latin-1 encoded text, but this can be changed to assist developers writing source code using other encodings.

The main purpose of this function is to preserve ASCII characters used in C strings. This is mainly useful for developers of non-internationalized software.

See also toLatin1(), unicode(), and QTextCodec.codecForCStrings().

### QChar QChar.toCaseFolded (self)

Returns the case folded equivalent of the character. For most Unicode characters this is the same as toLowerCase().

### int QChar.toCaseFolded (int ucs4)

This is an overloaded function.

Returns the case folded equivalent of the UCS-4-encoded character specified by ucs4. For most Unicode characters this is the same as toLowerCase().

### str QChar.toLatin1 (self)

Returns the Latin-1 character equivalent to the QChar, or 0. This is mainly useful for non-internationalized software.

See also toAscii(), unicode(), and QTextCodec.codecForCStrings().

### QChar QChar.toLower (self)

Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the character itself.

### int QChar.toLower (int ucs4)

This is an overloaded function.

Returns the lowercase equivalent of the UCS-4-encoded character specified by ucs4 if the character is uppercase or titlecase; otherwise returns the character itself.

### QChar QChar.toTitleCase (self)

Returns the title case equivalent if the character is lowercase or uppercase; otherwise returns the character itself.

### int QChar.toTitleCase (int ucs4)

This is an overloaded function.

Returns the title case equivalent of the UCS-4-encoded character specified by ucs4 if the character is lowercase or uppercase; otherwise returns the character itself.

### QChar QChar.toUpper (self)

Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the character itself.

### int QChar.toUpper (int ucs4)

This is an overloaded function.

Returns the uppercase equivalent of the UCS-4-encoded character specified by ucs4 if the character is lowercase or titlecase; otherwise returns the character itself.

### int QChar.unicode (self)

Returns a reference to the numeric Unicode value of the QChar.

### UnicodeVersion QChar.unicodeVersion (self)

Returns the Unicode version that introduced this character.

### UnicodeVersion QChar.unicodeVersion (int ucs4)

This is an overloaded function.

Returns the Unicode version that introduced the character specified in its UCS-4-encoded form as ucs4.

### QString QChar.__add__ (self, QString s2)

### bool QChar.__eq__ (self, QChar c2)

### bool QChar.__ge__ (self, QChar c2)

### bool QChar.__gt__ (self, QChar c2)

### int QChar.__hash__ (self)

### bool QChar.__le__ (self, QChar c2)

### bool QChar.__lt__ (self, QChar c2)

### bool QChar.__ne__ (self, QChar c2)

### str QChar.__repr__ (self)

### str QChar.__str__ (self)

### unicode QChar.__unicode__ (self)