PDA

View Full Version : Strange transparent painting behaviour



naresh
21st March 2006, 21:40
I'm trying to do my own tooltips for my QTreeView, and i've created my own tooltip basing on Qt4 source... I want it to have transparent background becouse in future i want it to have inregular shape image background (or standard rectangle bg). So atm i'm trying to draw standard rectangle bg but transparent (simply dont paint background just content). Here is some code


void rosterWidget::paintToolTip(const QModelIndex &idx, const QPoint &pos, QWidget *w) // JUST SHOW TOOLTIP
{
if(rosterTipLabel::instance && rosterTipLabel::instance->index()==idx)
return;

int scr;
if (QApplication::desktop()->isVirtualDesktop())
scr = QApplication::desktop()->screenNumber(pos);
else
scr = QApplication::desktop()->screenNumber(w);

QPoint p = pos;
p += QPoint(2,
#ifdef Q_WS_WIN
24
#else
16
#endif
);

rosterTipLabel *label=new rosterTipLabel(idx,QApplication::desktop()->screen(scr));
label->move(p);
label->show();
}


rosterTipLabel::rosterTipLabel(const QModelIndex &index,QWidget *parent): QLabel(parent, Qt::ToolTip)
{
delete instance;
instance=this;

setAutoFillBackground(TRUE);
setFrameStyle(QFrame::NoFrame);
setAlignment(Qt::AlignLeft);
// setAttribute(Qt::WA_NoSystemBackground); // I WAS TRYING THIS WITH SAME EFFECT AS WA_OpaquePaintEvent
setAttribute(Qt::WA_OpaquePaintEvent);

qApp->installEventFilter(this);
hideTimer.start(10000, this);
img=(index.model()->data(index,FotoRole)).value<QImage>();
status=(index.model()->data(index,Qt::DecorationRole)).value<QImage>();
nick=(index.model()->data(index,Qt::DisplayRole)).toString();
descr=(index.model()->data(index,DescriptionRole)).toString();
idx=index;

QPalette pal( QColor(255,255,220,255) /*windowText*/,
QColor(255,255,220,255) /*button*/,
QColor(255,255,220,255) /*light*/,
QColor(255,255,220,255) /*dark*/,
QColor(255,255,220,255) /*mid*/,
QColor(255,255,220,255) /*text*/,
QColor(255,255,220,255) /*bright_text*/,
QColor(255,255,220,255)/*base*/,
QColor(255,255,220,255)/*window*/);

qDebug()<<(pal.window()).isOpaque(); //always prints true

setPalette(pal);
}


void rosterTipLabel::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
painter.setBackgroundMode(Qt::TransparentMode);
//SIMPLE PNG IMAGE JUST A SHAPE WITH NO BACKGROUND
}

In thumbnail it seems that it is a bit transparent (becouse as a background i can see part of my screen). With code i posted background for my tip paints whole black... I have no more ideas what to do... I've read http://doc.trolltech.com/qq/qq16-background.html but i think i didn't understand it well

//EDIT
I forgot to add that im using Qt 4.1.1 version

wysota
28th September 2006, 08:37
You should use QWidget::setMask() to tell the paint engine which parts of the widget should be visible.