O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

The state variable is a bitmask holding the possible states of the item. You can check its value against the values of the QStyle::StateFlag parameter using bitwise operators. In the preceding case, the state variable is checked against the State_Selected parameter. If this flag is set, we use green color for the pen.

The type of state is QFlags<StateFlag>. So, instead of using the bitwise operator to test whether a flag is set, you can use the convenient function testFlag().

Used with the preceding example, it would be as follows:

if (option->state.testFlag(QStyle::State_Selected)) {  

The most important states you can use with items are described in the following table:

State Description

State_Enabled

Indicates ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required