Results 1 to 2 of 2

Thread: QTreeWidgetItems, how to make all ttransaprent to see QTreeWidget background

  1. #1
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:
    Qt Code:
    1. void qtg_QTreeWidget::paintEvent(QPaintEvent *event)
    2. {
    3.  
    4.  
    5. QPainter painter(viewport());
    6. QImage image("./background.png");
    7. QRect rect(x(),y(),image.height (),image.width());
    8. qDebug () <<"paint" << x() << y() << image.height () <<image.width();
    9. painter.drawImage(rect, image);
    10. painter.end();
    11. QTreeWidget::paintEvent(event);
    12. };
    To copy to clipboard, switch view to plain text mode 
    TreeWidgetItem
    Qt Code:
    1. gui_laucher::gui_laucher(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. setupTray();
    5. int y= m_tray->geometry().y() ;
    6. int x= m_tray->geometry().x() ;
    7. setGeometry(x+3,y+3,300,320);
    8. setAttribute(Qt::WA_TranslucentBackground);
    9. QStringList labels;
    10. labels << tr("Software");
    11.  
    12. m_treeWidget = new qtg_QTreeWidget(this);
    13. setStyleSheet("QTreeView::item {background-color :rgba(255,255,255,0%);}");
    14. xmlparser();
    15. }
    To copy to clipboard, switch view to plain text mode 

    I also try this:
    Qt Code:
    1. qtg_QTreeWidgetItem::qtg_QTreeWidgetItem(QTreeWidgetItem *parent) :
    2. {
    3. m_pProcessPath="nopath";
    4. m_pStringParameters="noparams";
    5.  
    6. setBackground(0,QBrush(Qt::transparent));
    7. }
    To copy to clipboard, switch view to plain text mode 

    I never can see the picture trought the item =(

  2. #2
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidgetItems, how to make all ttransaprent to see QTreeWidget background

    Solved:
    Qt Code:
    1. void qtg_QTreeWidget::drawRow(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
    2. {
    3.  
    4. /* Altro metodo per disegnare la pixmap:
    5.   la recupero così:
    6.   QTreeWidgetItem * item = this->itemFromIndex(idx);
    7.   la drawo così:
    8.   p->drawPixmap(im,yPixmap,16,16,item->icon(0).pixmap(16,16));
    9.  
    10. */
    11. for (int col = 0; col < columnCount(); ++col)
    12. {
    13. QModelIndex s = idx.sibling(idx.row(), col);
    14. if (s.isValid())
    15. {
    16. // Recupero il testo dell'item
    17. QString szText=idx.data(Qt::DisplayRole).toString();
    18. // Recupero la pixmap dell'item
    19. QPixmap myPix = qvariant_cast<QIcon>(idx.data(Qt::DecorationRole)).pixmap(opt.decorationSize);
    20. // Mi recupero il rettangolo dove disegnare
    21. int x = visualRect(s).left();
    22. int y = visualRect(s).top();
    23. int w = visualRect(s).width();
    24. int h = visualRect(s).height();
    25. QRect cRect(x,y,w,h);
    26. // Mi calcolo la y dell'icona dell'item
    27. int yPixmap = (y + (h / 2 - 8));
    28. /* Posso cominciare a disegnare l'item, non disegnerò lo sfondo
    29.   perchè lo voglio trasparente, altrimenti avrei fatto così:
    30.   QImage image("percorso");
    31.   QRect rect(opt.rect);
    32.   p->drawImage(rect, image);
    33.   */
    34. // Disegno l'icona
    35. p->drawPixmap(x,yPixmap,myPix.width(),myPix.height(),myPix);
    36. // Mi sposto verso destra del rettangolo dell'item della lunghezza della pixmap + 2 per distaccarmi
    37. // e disegno il testo
    38. cRect.setLeft(cRect.left() + myPix.width()+2);
    39. p->drawText(cRect,Qt::AlignLeft | Qt::AlignVCenter,szText);;
    40. // Mi sposto verso sinistra del rettangolo visuale dell'item sottraendo la lunghezza della mia pixmap + 2
    41. // e chiamo la funzione delle QT che disegna le branches passandogli il rettangolo giusto
    42. cRect.setRight(cRect.left() - (myPix.width()+2));
    43. QTreeView::drawBranches(p,cRect,idx);
    44. }
    45.  
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to make a label be on the background?
    By Bong.Da.City in forum Newbie
    Replies: 3
    Last Post: 6th September 2010, 11:37
  2. How to make my app to play background music
    By HelloDan in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2009, 09:17
  3. Replies: 1
    Last Post: 21st November 2008, 16:06
  4. make background invisible
    By punit.doshi.85 in forum Qt Programming
    Replies: 1
    Last Post: 1st October 2008, 10:48
  5. Trying to change the background of a QTreeWidget
    By vycke in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 20:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.