QGraphicsItem::paint
has the following signature:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
When I create custom QGraphicsItem
s, I have to provide an implementation for this function. The thing is... I never need to use the option
and widget
parameters, but I can't just remove them for obvious reasons. I always see these compiler warnings:
warning: unused parameter ‘widget’
warning: unused parameter ‘option’
Is there a proper to get rid of these warnings? I know I can hide them by mentioning the unused parameters in the function, but this is a very dirty solution and I'd like to know if there are better options.
Either omit the parameter name:
void paint( ..., QWidget* ) {
or use the Q_UNUSED macro:
void paint( ..., QWidget* widget ) {
Q_UNUSED( widget )
...
Don't provide parameter names to the unused parameters. For example (I'm not sure what your "event" refers to), to get rid of warning: unused parameter ‘option’
, change your signature to:
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /* unused */, QWidget *widget)
(The /* unused */
tag is unnecessary as far as the warning goes, but it's useful for the human reader, I find.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With