Results 1 to 4 of 4

Thread: How to change the QTreeWidgetItem background images on selected event in style sheet.

  1. #1
    Join Date
    Jun 2014
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Thumbs up How to change the QTreeWidgetItem background images on selected event in style sheet.

    Dear All,

    I am newbie in qt gui development, i have created the QTreeWidget Class and added the QTreeWidgetItems liks,

    class xyz: public QTreeWidget
    {
    QOBJECT

    public:
    xyx (QWidget *inParent = 0 );

    private:
    QTreeWidgetItem *aItem;
    };

    in c file i have created the QTreeWidgetItem like this

    QTreeViewItem *a1 = new QTreeWidgetItem(this);
    a1->setBackground = (0,QBrush(QImage(":/Images/001.png")));

    QTreeViewItem *a2 = new QTreeWidgetItem(this);
    a2->setBackground = (0,QBrush(QImage(":/Images/003.png")));

    the images are displayed successfully, in the run time when the a2item selected the 003.png image will display in the a1 and when the a2 item selected the 004.png image will display i am using style sheet.

    please give suggestions for me to display the different images in the item when the item selected.

    sorry for the bad english.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the QTreeWidgetItem background images on selected event in style sh

    Try below style sheet in which you can replace background-color with image.
    a1->setStyleSheet(" QTreeWidget::item { background-color: yellow; } QTreeWidget::item:selected { background-color: blue; }");

  3. #3
    Join Date
    Jun 2014
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: How to change the QTreeWidgetItem background images on selected event in style sh

    Thanks for your reply,

    One mistake in my code

    QTreeViewItem *a1 = new QTreeWidgetItem(this);
    a1->setBackground = (0,QBrush(QImage(":/Images/001.png")));

    it should be

    QTreeWidgetItem *a1 = new QTreeWidgetItem(this);
    a1->setBackground = (0,QBrush(QImage(":/Images/001.png")));

    in QTreeWidgetItem there is no memeber function called setStyleSheet so how can we fix this issue.

    Thanks in advance

  4. #4
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the QTreeWidgetItem background images on selected event in style sh

    Remove your setBackground function call it is not required if you are calling setStyleSheet function on widget.
    Try calling setStyleSheet function as I said and it should work.

Similar Threads

  1. How To Change Style Sheet for QCalendarWidget
    By jthacker in forum Qt Programming
    Replies: 15
    Last Post: 4th March 2016, 15:28
  2. Replies: 1
    Last Post: 10th February 2011, 20:32
  3. Style Sheet with Gradient Background
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 27th July 2010, 05:23
  4. Style Sheet Syntax background
    By Tondog in forum Qt Programming
    Replies: 5
    Last Post: 28th April 2010, 07:21
  5. multiple images in style sheet
    By CopyrightPhilly in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2007, 17:28

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.