QTreeWidgetItems, how to make all ttransaprent to see QTreeWidget background
Hello to all, sorry my english =)
My problem is that:
I set a background to my QTreeWidget,
I populate my tree with QTreeWidgetItems and i want to see the background trought the items.
Try with setStyleSheet of the TreeWidget:item : nothing how can i do?
TreeWidget:
Code:
{
QImage image
("./background.png");
QRect rect
(x
(),y
(),image.
height (),image.
width());
qDebug () <<"paint" << x() << y() << image.height () <<image.width();
painter.drawImage(rect, image);
painter.end();
};
TreeWidgetItem
Code:
gui_laucher
::gui_laucher(QWidget *parent
){
setupTray();
int y= m_tray->geometry().y() ;
int x= m_tray->geometry().x() ;
setGeometry(x+3,y+3,300,320);
setAttribute(Qt::WA_TranslucentBackground);
labels << tr("Software");
m_treeWidget = new qtg_QTreeWidget(this);
setStyleSheet("QTreeView::item {background-color :rgba(255,255,255,0%);}");
xmlparser();
}
I also try this:
Code:
{
m_pProcessPath="nopath";
m_pStringParameters="noparams";
setBackground
(0,
QBrush(Qt
::transparent));
}
I never can see the picture trought the item =(
Re: QTreeWidgetItems, how to make all ttransaprent to see QTreeWidget background
Solved:
Code:
{
/* Altro metodo per disegnare la pixmap:
la recupero così:
QTreeWidgetItem * item = this->itemFromIndex(idx);
la drawo così:
p->drawPixmap(im,yPixmap,16,16,item->icon(0).pixmap(16,16));
*/
for (int col = 0; col < columnCount(); ++col)
{
if (s.isValid())
{
// Recupero il testo dell'item
QString szText
=idx.
data(Qt
::DisplayRole).
toString();
// Recupero la pixmap dell'item
QPixmap myPix
= qvariant_cast<QIcon>
(idx.
data(Qt
::DecorationRole)).
pixmap(opt.
decorationSize);
// Mi recupero il rettangolo dove disegnare
int x = visualRect(s).left();
int y = visualRect(s).top();
int w = visualRect(s).width();
int h = visualRect(s).height();
// Mi calcolo la y dell'icona dell'item
int yPixmap = (y + (h / 2 - 8));
/* Posso cominciare a disegnare l'item, non disegnerò lo sfondo
perchè lo voglio trasparente, altrimenti avrei fatto così:
QImage image("percorso");
QRect rect(opt.rect);
p->drawImage(rect, image);
*/
// Disegno l'icona
p->drawPixmap(x,yPixmap,myPix.width(),myPix.height(),myPix);
// Mi sposto verso destra del rettangolo dell'item della lunghezza della pixmap + 2 per distaccarmi
// e disegno il testo
cRect.setLeft(cRect.left() + myPix.width()+2);
p->drawText(cRect,Qt::AlignLeft | Qt::AlignVCenter,szText);;
// Mi sposto verso sinistra del rettangolo visuale dell'item sottraendo la lunghezza della mia pixmap + 2
// e chiamo la funzione delle QT che disegna le branches passandogli il rettangolo giusto
cRect.setRight(cRect.left() - (myPix.width()+2));
}
}
}