MusicListHeaderView
::MusicListHeaderView(QWidget* parent
): QHeaderView(Qt
::Horizontal, parent
){
hoverIndex = -1;
}
void MusicListHeaderView
::paintSection(QPainter* painter,
const QRect
& rect,
int logicalIndex
) const {
drawBackground(painter, rect, logicalIndex);
drawText(painter, rect, logicalIndex);
}
bool MusicListHeaderView
::event(QEvent* event
) {
switch(event->type())
{
{
int hoverIndex = logicalIndexAt(hover->pos());
}
break;
{
hoverIndex = -1;
}
break;
{
hoverIndex = logicalIndexAt(hover->pos());
}
break;
}
}
void MusicListHeaderView
::drawBackground(QPainter* painter,
const QRect
& rect,
int index
) const {
if(hoverIndex == index)
painter
->fillRect
(rect,
QColor(0xF0, 0xF0, 0xF0
));
else
painter->fillRect(rect, Qt::white);
painter
->setPen
(QColor(0xF0, 0xF0, 0xF0
));
painter->drawLine(rect.x(), rect.y()+rect.height()-1, rect.x()+rect.width(), rect.y()+rect.height()-1); // horizontal
// painter->drawLine(rect.x()+rect.width()-1, rect.y(), rect.x()+rect.width()-1, rect.y()+rect.height()); // vertical
}
void MusicListHeaderView
::drawText(QPainter* painter,
const QRect
& rect,
int index
) const {
painter->setPen(Qt::black);
painter
->setFont
(QFont("Corbel",
9,
QFont::Bold));
painter->drawText(rect.adjusted(10, 0, 10, 0), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, final);
}
MusicListHeaderView::MusicListHeaderView(QWidget* parent): QHeaderView(Qt::Horizontal, parent)
{
hoverIndex = -1;
}
void MusicListHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
{
drawBackground(painter, rect, logicalIndex);
drawText(painter, rect, logicalIndex);
}
bool MusicListHeaderView::event(QEvent* event)
{
switch(event->type())
{
case QEvent::HoverEnter:
{
QHoverEvent* hover = static_cast<QHoverEvent*>(event);
int hoverIndex = logicalIndexAt(hover->pos());
}
break;
case QEvent::HoverLeave:
{
hoverIndex = -1;
}
break;
case QEvent::HoverMove:
{
QHoverEvent* hover = static_cast<QHoverEvent*>(event);
hoverIndex = logicalIndexAt(hover->pos());
}
break;
}
return QHeaderView::event(event);
}
void MusicListHeaderView::drawBackground(QPainter* painter, const QRect& rect, int index) const
{
if(hoverIndex == index)
painter->fillRect(rect, QColor(0xF0, 0xF0, 0xF0));
else
painter->fillRect(rect, Qt::white);
painter->setPen(QColor(0xF0, 0xF0, 0xF0));
painter->drawLine(rect.x(), rect.y()+rect.height()-1, rect.x()+rect.width(), rect.y()+rect.height()-1); // horizontal
// painter->drawLine(rect.x()+rect.width()-1, rect.y(), rect.x()+rect.width()-1, rect.y()+rect.height()); // vertical
}
void MusicListHeaderView::drawText(QPainter* painter, const QRect& rect, int index) const
{
QFontMetrics metric(painter->font());
QString final = "test";
painter->setPen(Qt::black);
painter->setFont(QFont("Corbel", 9, QFont::Bold));
painter->drawText(rect.adjusted(10, 0, 10, 0), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, final);
}
To copy to clipboard, switch view to plain text mode
Bookmarks