PDA

View Full Version : QStyledItemDelegate not working cross platform



Berryblue031
24th September 2013, 07:59
I am using Qt 5.1.1 and have a QListView with a custom QStyledItemDelegate inside a Widget with the Qt::Popup flag to make a special dropdown in my app.



void MyCustomItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
qDebug() << option.state;
}

On Windows 7 everything works fine and the flags from the QStyleOptionViewItem are as expected, my app renders a nice list that reacts to MouseOver & Selected


..
QStyle::State( "Enabled | Selected" )
QStyle::State( "Enabled" )
QStyle::State( "Enabled | MouseOver" )
QStyle::State( "Enabled" )
...


HOWEVER on Linux and Windows XP the flags are not as expected - MouseOver state is never set and all Items are receiving Active


...
QStyle::State( "Active | Enabled | HasFocus | Selected" )
QStyle::State( "Active | Enabled" )
QStyle::State( "Active | Enabled" )
QStyle::State( "Active | Enabled" )
...

Is this expected? Is there a work around (besides checking if the cursor is within option.rect every time)

anda_skoa
24th September 2013, 09:15
Might be more related to the style being used than to the delegate.
Which style are you using on, e.g. Linux? Have you tried a different one?

Cheers,
_

Berryblue031
24th September 2013, 09:38
I don't see how the style would affect the state flags? It's works the other way around doesn't it? Depending on the state flags the style will choose how to render?

On Linux and Windows XP I am using the default styles - if I wasn't using a custom delegate for painting and was just styling the QListViewItems in the stylesheets with QListView::item:hover all platforms would work fine so it should be possible to detect hover even on other platforms.

anda_skoa
24th September 2013, 12:05
Styles can do active things as well, e.g. listen to events and triggering changes, etc.

They are the most likely cause when something is different visualization wise.
What happens if you run the application on Windows 7 but using the Windows XP style?

Cheers,
_