Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Background in QTableWidget
Qt 6.11 is out! See what's new in the release blog

Background in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dyzio163
    wrote on last edited by
    #1

    Hi. I have class inherited from QTableWidget. I want to set background from file, but line
    "setStyleSheet("background-image: url("board.jpg");");" or
    setStyleSheet("background-image: url(./board.jpg);") doesn't work... What is solution?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Binary91
      wrote on last edited by
      #2

      Hi and welcome to DevNet!

      I think this can be done via QPalette/QPixmap:
      @ QTableWidget* table = new QTableWidget;

      QPalette palette = table->palette();
      QPixmap jpgImage( "board.jpg");
      palette.setBrush(QPalette::Base, QBrush(jpgImage));
      table->setPalette(palette);@
      

      Try it, I didn't test it..

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dyzio163
        wrote on last edited by
        #3

        Hmmm. Where should be file board.jpg? In folder "build-Checkers_V01-Desktop_Qt_5_3_MSVC2013_64bit-Debug" or just in "Checkers_V01"?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Binary91
          wrote on last edited by
          #4

          It depends.. Try it in both folders to see if it works. Or use an absolute path like "C:\Path\To\Image\board.jpg"

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            [quote author="Binary91" date="1417095175"]Hi and welcome to DevNet!
            @QPixmap jpgImage( "board.jpg");@
            [/quote]

            This is a relative path so the file must be in the same folder as the executable.

            On a related note, since you are using Qt, you should use the *nix forward slash notation, it will avoid many problem with paths

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved