KAction::setIconSet

Peter Hedlund peter at peterandlinda.com
Thu Apr 29 03:07:48 BST 2004


Hi All,

I tried this in kde-devel, but didn't really get an answer. I hope it's OK to 
post here. I try to generate icons for some actions in code. The icon 
represents a character that can be configured by the user. Thus the icon 
needs to be recreated from time to time. The code below works, but there are 
a couple of problems:

1. In a toolbar the icon size will always be 22, I guess that's the default. 
If I change size using the toolbar context menu the displayed icon size isn't 
changed.

2. The KEditToolbar dialog will always use the icon size I create in code (32 
in the example below).

How can I get around these problems? I'm running KDE cvs from about a week 
ago.

Thanks,
Peter

void KWordQuizApp::updateSpecialCharIcons( )
{
  for (int i = 0; i < 9; i++){
    QString s = (QString) Config().m_specialCharacters[i];
    QRect r(2, 2, 30, 30);

    ///A font to draw the character with
    QFont font("sans");
    font.setPixelSize(26);
    font.setWeight(QFont::Bold);
    
    ///Create the pixmap        
    QPixmap pm(32, 32);
    pm.fill(Qt::white);
    QPainter p(&pm);
    p.setFont(font);
    p.setPen(Qt::blue);
    p.drawText(r, Qt::AlignCenter, s);
    
    ///Create transparency mask
    QBitmap bm(32, 32);
    bm.fill(Qt::color0);
    QPainter b(&bm);
    b.setFont(font);
    b.setPen(Qt::color1);
    b.drawText(r, Qt::AlignCenter, s);
    
    ///Mask the pixmap
    pm.setMask(bm);   
    
    KAction * act = actionCollection()->action("char_" + QString::number(i + 
1));
    act->setIconSet(QIconSet(pm));
    act->setToolTip(i18n("Inserts the character %1").arg(s));
  }
}




More information about the kde-core-devel mailing list