Results 1 to 4 of 4

Thread: Setting Dynamic Back ground image on QTableWidget

  1. #1
    Join Date
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Post Setting Dynamic Back ground image on QTableWidget

    Hi There.

    Simple question, but I can't figure out how to make it work.
    I want to set an image to be always at the bottom right hand corner of my QTableWidget. I've got this to work by setting the following:

    Qt Code:
    1. myTableWidget->viewport()->setStyleSheet("background-image: url(:/images/myimage.png); background-repeat:no-repeat;background-attachment:fixed;background-position:bottom right;");
    To copy to clipboard, switch view to plain text mode 

    This work exactly as I wanted. However I've now come to enhance some features and my image now needs to be dynamic. I have a class that return a QPixmap with the appropriate image. I don't want to save the physical file to a harddrive because I may have multiple version of the same control open at the same time all requireing different images, and I don't want to clog up the users hard drive with temporary images.

    I've tried lots of different variation of the following all with little success.

    Qt Code:
    1. QPalette pal = myTableWidget->viewport()->palette();
    2. pal.setBrush( myTableWidget->viewport()->backgroundRole(), QBrush( QPixmap(":/images/myimage.png")) );
    3. myTableWidget->viewport()->setPalette( pal );
    To copy to clipboard, switch view to plain text mode 

    This sort of works, but it's on the top right and when I scroll the table columns from left to right the image breaks up, also the image scrolls and is not fixed to possition.

    Anyhelp would be apprechiated.
    Last edited by dholliday; 16th May 2011 at 13:25.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting Dynamic Back ground image on QTableWidget

    Override the paint event and draw the image yourself before calling the base class implementation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting Dynamic Back ground image on QTableWidget

    Quote Originally Posted by wysota View Post
    Override the paint event and draw the image yourself before calling the base class implementation.
    Sorry didn't mention. The code that I said doesn't work correctly is being used inside the paint event before the base class implementation. It work OK. But when I add columns to my control and then scroll left and right, it breaks the image up. So I must be doing something wrong.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting Dynamic Back ground image on QTableWidget

    Hard to say without seeing this code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 19th January 2011, 13:49
  2. Changing Qt's green application back ground color
    By anafor2004 in forum Qt Programming
    Replies: 0
    Last Post: 17th June 2009, 12:58
  3. qcombobox back ground coloring
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 20:29
  4. qCheckbox back ground color
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 19:44
  5. problem with the back ground image
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2006, 22:34

Tags for this Thread

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.