PDA

View Full Version : QHeaderView Sort Indicator sizing



vycke
23rd September 2009, 16:45
I have a project with multiple QTableViews with sortable columns. Unfortunately, my users dislike the size of the arrow for the Sort Indicator in the QHeaderView. I've seen that I can change the image in a style sheet, but is there an easy way to just resize what's currently there? I ask, because the image would have to be skin color sensitive (I don't want black on black or something like that -- unless I could make sure it's sunken like the current arrow).

Has anyone done/tried something like this? (I couldn't find anything on the forums, and usually I'm pretty good with searches.)

Thanks,
Vycke

aamer4yu
24th September 2009, 10:48
How about reimplementing / subclassing the headerview ??
or may be style sheets might also be a good option as u said.

vycke
25th September 2009, 16:44
Well, I tried the Style Sheet... which worked, except you can't use the Palette with Style Sheets (and since I have user-selectable palettes, able to be changed on the fly, this isn't good).

The QHeaderView is subclassed already in the app, but I have been unable to get paintSection() to override properly -- it appears that all the sections wind up selected/sunken, or it doesn't update the old selected section when you select a new one. I'm probably doing it wrong somehow, so I'll go over some other code I have (that rotates headers 90 degrees) and try this again.

If anyone else has a suggestion, I'm open to it :)

Vycke

vycke
1st October 2009, 15:53
Ok, just so anyone else trying to do the same thing has an answer, here's what I did:


//In the constructor for the Header subclass
m_styleSet = "QHeaderView::down-arrow { image: url(:/images/down_arrow.png); width: 13px; height:9px; subcontrol-position: bottom right;} "
"QHeaderView::up-arrow { image: url(:/images/up_arrow.png); subcontrol-position: bottom right; } "
"QHeaderView:: section { color: %1; background-color: %2; }";

QString setStyle = m_styleSet.arg(QApplication::palette().windowText( ).color().name()).arg(QApplication::palette().wind ow().color.name());
this->setStyleSheet(setStyle);


I installed an event filter:



bool CHeaderView::eventFilter(QObject* obj, QEvent* event)
{
if ((event->type() == QEvent::ApplicationPaletteChange) ||
(event->type() == QEvent::PaletteChange))
{
QString setStyle = m_styleSet.arg(QApplication::palette().windowText( ).color().name()).arg(QApplication::palette().wind ow().color.name());
this->setStyleSheet(setStyle);
return true;
}
return QHeaderView::eventFilter(obj,event);
}


This allows for palette changes & still gives me the arrow that I want (the .pngs)

Vycke