PDA

View Full Version : QStyle not styling



irudkin
25th April 2006, 10:52
Hi

Using Qt3.3.3. I have a QToolbutton derive class where I am trying use a style to help the button to conform to OS GUI used. I can set the QStyle drawPrimitive or QStyle drawComplex so the graphic is what I want however I cannot change the colour to indicate for example hover or mouse click. :confused:


//++ ------------------------------------------------------------------------------------
void RDWinWithWinMenuBtn_c::paintEvent( QPaintEvent * /*vpEvent*/ )
{
// RD_DEV_IOR_FACT
// The colorGroup parameter in drawComplexControl appears not to be used (look at Qt source code)
// so doing this
// QColorGroup colorGrp; <- default all black
// makes not difference to the button color!!
//
// Also style does not change when windows theme changes. Is this not the idea of QStyles?

QPainter painter( this );
//style().drawComplexControl( QStyle::CC_ToolButton, &painter, this, rect(), colorGroup() );

// Test code to change to ANY color or style! Not!
QStyle::SFlags sf = QStyle::Style_Raised;
QPalette pl = palette();
QColorGroup cga = pl.active();
QColorGroup cgi = pl.inactive();
QColorGroup cgBtn;
if( hasMouse() )
{
if( m_bBtnIsClicked )
{
sf = QStyle::Style_Down;
cga.setColor( QColorGroup::Background, QColor( Qt::green ) );
cgBtn = cga;
}
else
{
sf = QStyle::Style_HasFocus;
cgi.setColor( QColorGroup::Background, QColor( Qt::blue ) );
cgBtn = cgi;
}
}

pl.setActive( cga );
pl.setInactive( cgi );
setPalette( pl );
style().drawControl( QStyle::CE_PushButton, &painter, this, rect(), cgBtn, sf );
}

void RDWinWithWinMenuBtn_c::mousePressEvent( QMouseEvent * vpEvent )
{
m_bBtnIsClicked = true;
}

void RDWinWithWinMenuBtn_c::mouseReleaseEvent( QMouseEvent * vpEvent )
{
m_bBtnIsClicked = false;
}

How do I get the style colour to be used? ATM I see a button but it does not 'animate' to show the user it is active or clicked on. It makes no difference what a style flag or colorGroup I feed it. :confused: