I eliminated the style sheets altogether and now I'm just changing the appearance of the buttons using setPalette(), but the problem still remains. The memory grows when changing the palette of the clicked one. If I keep clicking button1, then button2, then button1, etc. etc. back and forth the memory grows each time. Pretty sure it's not a leak somewhere else in the code because when I comment out the setPalette() call, the memory does not grow. Here's some code that may help clarify:
void MenuManager
::changeButtonAppearance( QPushButton * button,
const QColor & bgColor,
const QColor & textColor,
int bgAlpha
) {
if( button )
{
theBgColor.setAlpha( bgAlpha );
p.
setColor( QPalette::Button, theBgColor
);
p.
setColor( QPalette::ButtonText, textColor
);
button->setPalette( p );
}
}
void MenuManager::changeButtonAppearance( QPushButton * button, const QColor & bgColor, const QColor & textColor, int bgAlpha )
{
if( button )
{
QPalette p( button->palette() );
QColor theBgColor( bgColor );
theBgColor.setAlpha( bgAlpha );
p.setColor( QPalette::Button, theBgColor );
p.setColor( QPalette::ButtonText, textColor );
button->setPalette( p );
}
}
To copy to clipboard, switch view to plain text mode
void MenuManager::resetButtonStyles()
{
for( int i = 0; i < buttons.count(); i++ )
{
changeButtonAppearance(
buttons.at( i ),
128 );
}
}
void MenuManager::resetButtonStyles()
{
for( int i = 0; i < buttons.count(); i++ )
{
changeButtonAppearance(
buttons.at( i ),
QColor( Qt::black ),
QColor( Qt::yellow ),
128 );
}
}
To copy to clipboard, switch view to plain text mode
void MenuManager::setButtonAsSelected( int index )
{
if( index >= 0 && index < buttons.count() )
{
resetButtonStyles();
changeButtonAppearance(
buttons.at( index ),
128 );
}
}
void MenuManager::setButtonAsSelected( int index )
{
if( index >= 0 && index < buttons.count() )
{
resetButtonStyles();
changeButtonAppearance(
buttons.at( index ),
QColor( Qt::red ),
QColor( Qt::yellow ),
128 );
}
}
To copy to clipboard, switch view to plain text mode
When I click a particular button, I call setButtonAsSelected() with an index depending on which button was clicked... intent is to set the background color of the button I clicked to red and set the other ones to black...
Bookmarks