Results 1 to 6 of 6

Thread: QTreeWidget backgroundcolor

  1. #1
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    4

    Post QTreeWidget backgroundcolor

    Hi,
    I'm trying to change the background color of a qtreewidget without sucess:

    QApplication *qa = new QApplication(argc, argv);
    QWidget *qw = new QWidget();
    QTreeWidget *tw = new QTreeWidget(qw);
    QStringList lst;
    lst.append(QString("testing"));
    QTreeWidgetItem *test = new QTreeWidgetItem(tw, lst);
    tw->setBackgroundColor(Qt::blue);
    What's wrong? I'm using qt 4.2

    In fact, I'm trying to change the color of a QGraphicsView (implemented in 4.2) ..
    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget backgroundcolor

    Quote Originally Posted by vmferreira
    What's wrong?
    QTreeWidgetItem::setBackgroundColor() takes two parameters.

    If you want to change the whole QTreeWidget background, try:
    Qt Code:
    1. QPalette p( treeWidget->palette() );
    2. p.setColor( QPalette::Base, Qt::blue );
    3. treeWidget->setPalette( p );
    To copy to clipboard, switch view to plain text mode 

    In fact, I'm trying to change the color of a QGraphicsView (implemented in 4.2)
    Then why you are bothering with QTreeWidgetItem? Try QGraphicsView::setBackgroundBrush().

  3. The following 2 users say thank you to jacek for this useful post:

    sector (9th August 2006), vmferreira (9th August 2006)

  4. #3
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    4

    Post Re: QTreeWidget backgroundcolor

    Thanks a lot jacek, your answer helped a lot.
    Now, I'm trying to get the view of the graphic transparent, in order to see a pixmap that is loaded from the widget parent, above is how I'm doing:

    QApplication *qa = new QApplication(argc, argv);
    QWidget *qd = new QWidget();
    QPixmap pix(":/images/bola_verde.png");
    qd->setBackgroundPixmap(pix);

    QGraphicsScene *scene = new QGraphicsScene(qd);
    QGraphicsView *view = new QGraphicsView ( scene, qd );
    view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    QBrush alphaBrush = view->palette().brush(QPalette::Base);
    QColor alphaColor(Qt::transparent);
    alphaBrush.setColor(alphaColor);
    //view->setBackgroundBrush(alphaBrush);
    view->setWindowOpacity(0.3);
    scene->setBackgroundBrush(alphaBrush);

    It does not work. This can be done? I don't think that mask() can solve my problem..

    Thanks

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget backgroundcolor

    Quote Originally Posted by vmferreira
    This can be done?
    Of course:
    Qt Code:
    1. QGraphicsScene *scene = new QGraphicsScene(qd);
    2. QGraphicsView *view = new QGraphicsView ( scene, qd );
    3. view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    4.  
    5. QPalette p( view->palette() );
    6. p.setBrush( QPalette::Base, Qt::NoBrush );
    7. view->setPalette( p );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by vmferreira
    I don't think that mask() can solve my problem..
    No, setMask() is for making "holes" in widgets.

  6. The following user says thank you to jacek for this useful post:

    vmferreira (9th August 2006)

  7. #5
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    4

    Question QGraphics backgroundcolor (transparent)

    Thanks again jacek, but now it didn't work
    My code:
    QApplication *qa = new QApplication(argc, argv);
    QWidget *qd = new QWidget();
    QPixmap pix(":/images/bola_verde.png");
    qd->setBackgroundPixmap(pix);

    QGraphicsScene *scene = new QGraphicsScene(qd);
    QGraphicsView *view = new QGraphicsView ( scene, qd );
    QPalette p( view->palette() );
    p.setBrush( QPalette::Base, Qt::NoBrush );
    view->setPalette( p );
    //scene->setBackgroundBrush(p.brush(QPalette::Base));
    This is my result:
    imagem.PNG

    Looks like there is another background before the widget's background. I've already tried removing scene's background, but it didn't work either..
    Last edited by vmferreira; 9th August 2006 at 20:02. Reason: Changing title

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphics backgroundcolor (transparent)

    Quote Originally Posted by vmferreira
    Looks like there is another background before the widget's background.
    It's hard to tell what's wrong without seeing the code, but setPalette() worked for me. Maybe you change the background afterwards? Or it's not a background, but part of the item?

  9. The following user says thank you to jacek for this useful post:

    vmferreira (9th August 2006)

Similar Threads

  1. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51
  2. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  3. How to capture resizing of QTreeWidget columns?
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 06:10
  4. QTreeWidget problem!!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2006, 11:47
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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
  •  
Qt is a trademark of The Qt Company.