- Game Programming using Qt 5 Beginner's Guide
- Pavel Strakhov Witold Wysota Lorenz Haas
- 71字
- 2021-08-27 18:31:07
Time for action – Reacting to an item's selection state
Standard items, when selected, change appearance (for example, the outline usually becomes dashed). When we're creating a custom item, we need to implement this feature manually. Let's make our item selectable in the View constructor:
SineItem *item = new SineItem(); item->setFlag(QGraphicsItem::ItemIsSelectable);
Now, let's make the graph line green when the item is selected:
if (option->state & QStyle::State_Selected) { pen.setColor(Qt::green); } painter->setPen(pen);