Remember QPersistentModelIndex rather than row for hover effect.
This commit is contained in:
parent
36f30b1ede
commit
c2cb367753
@ -40,7 +40,7 @@ static const int EXTENDED_PARTITION_MARGIN = 4;
|
|||||||
|
|
||||||
PartitionBarsView::PartitionBarsView( QWidget* parent )
|
PartitionBarsView::PartitionBarsView( QWidget* parent )
|
||||||
: QAbstractItemView( parent )
|
: QAbstractItemView( parent )
|
||||||
, m_hoveredRow( -1 )
|
, m_hoveredIndex( QModelIndex() )
|
||||||
{
|
{
|
||||||
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||||
setFrameStyle( QFrame::NoFrame );
|
setFrameStyle( QFrame::NoFrame );
|
||||||
@ -113,7 +113,8 @@ PartitionBarsView::drawSection( QPainter* painter, const QRect& rect_, int x, in
|
|||||||
|
|
||||||
|
|
||||||
QColor borderColor;
|
QColor borderColor;
|
||||||
if ( index.row() == m_hoveredRow )
|
if ( m_hoveredIndex.isValid() &&
|
||||||
|
index == m_hoveredIndex )
|
||||||
{
|
{
|
||||||
borderColor = palette().highlight().color();
|
borderColor = palette().highlight().color();
|
||||||
painter->setBrush( color.lighter( 115 ) );
|
painter->setBrush( color.lighter( 115 ) );
|
||||||
@ -362,15 +363,15 @@ void
|
|||||||
PartitionBarsView::mouseMoveEvent( QMouseEvent* event )
|
PartitionBarsView::mouseMoveEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
QModelIndex candidateIndex = indexAt( event->pos() );
|
QModelIndex candidateIndex = indexAt( event->pos() );
|
||||||
int oldHoveredRow = m_hoveredRow;
|
QPersistentModelIndex oldHoveredIndex = m_hoveredIndex;
|
||||||
if ( candidateIndex.isValid() )
|
if ( candidateIndex.isValid() )
|
||||||
{
|
{
|
||||||
m_hoveredRow = candidateIndex.row();
|
m_hoveredIndex = candidateIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_hoveredRow = -1;
|
m_hoveredIndex = QModelIndex();
|
||||||
|
|
||||||
if ( oldHoveredRow != m_hoveredRow )
|
if ( oldHoveredIndex != m_hoveredIndex )
|
||||||
{
|
{
|
||||||
viewport()->repaint();
|
viewport()->repaint();
|
||||||
}
|
}
|
||||||
@ -380,9 +381,9 @@ PartitionBarsView::mouseMoveEvent( QMouseEvent* event )
|
|||||||
void
|
void
|
||||||
PartitionBarsView::leaveEvent( QEvent* event )
|
PartitionBarsView::leaveEvent( QEvent* event )
|
||||||
{
|
{
|
||||||
if ( m_hoveredRow > -1 )
|
if ( m_hoveredIndex.isValid() )
|
||||||
{
|
{
|
||||||
m_hoveredRow = -1;
|
m_hoveredIndex = QModelIndex();
|
||||||
viewport()->repaint();
|
viewport()->repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ private:
|
|||||||
QModelIndex index;
|
QModelIndex index;
|
||||||
};
|
};
|
||||||
inline QPair< QVector< Item >, qreal > computeItemsVector( const QModelIndex& parent ) const;
|
inline QPair< QVector< Item >, qreal > computeItemsVector( const QModelIndex& parent ) const;
|
||||||
int m_hoveredRow;
|
QPersistentModelIndex m_hoveredIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARTITIONPREVIEW_H */
|
#endif /* PARTITIONPREVIEW_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user