开发者

Qt mouse cursor transparency

I would like to change the stock cursor with a translucent one, a simple filled circle, of various sizes, depending on the level of zoom in the underlying widget (say, RGBA = 200, 200, 200, 128).

Is this at all possible with Qt? If not, is it a limitation in Qt or the underlying libs? Do you have suggestions as to how this could be accomplished by other 开发者_高级运维means, e.g., hiding the cursor and overlaying a transparent pixmap at the cursor position (albeit slower)? TIA


QCursor can take a QPixmap which does support alpha channel. So I don't see why it can't be done.


I just figured this out for a project of my own. I did it with this code in the constructor of the relevant widget:

m_LPixmap = new QPixmap(32,32);
m_LPixmap->fill(Qt::transparent); // Otherwise you get a black background :(
QPainter painter(m_LPixmap);
QColor red(255,0,0,128);

painter.setPen(Qt::NoPen);        // Otherwise you get an thin black border
painter.setBrush(red);

painter.drawEllipse(0,0,32,32);
m_Cursor = QCursor(*m_LPixmap);
setCursor(m_Cursor);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜