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. I want to add image to the items in the table view

I want to add image to the items in the table view

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 11.9k Views
  • 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.
  • M Offline
    M Offline
    M_31
    wrote on last edited by
    #1

    Hi All,
    i want to have a control of tableview format to list many images on a single item value.
    So shall i go with QTableView or QTableWidget.?...which is the best & easiest way to do that?

    Please help me..

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dakron
      wrote on last edited by
      #2

      Please try to find a difference between these two, try to implement something and if you have any problems then let us know.
      You can start from the examples from qt source code e.g. spinboxdelegate.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        [quote author="M_31" date="1310140082"]Hi All,
        i want to have a control of tableview format to list many images on a single item value.
        So shall i go with QTableView or QTableWidget.?...which is the best & easiest way to do that?
        [/quote]
        What do you mean by the highlighted part of your question exactly? Do you need to put more than one image in a cell of a table? If so, than neither QTableView nor QTableWidget is going to help you do that directly. Both are only able to display a single image in a cell normally. If you want to go beyond that, you'll need to do a bit of programming yourself.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          M_31
          wrote on last edited by
          #4

          Andre...

          I have used QTableWidgetItem under QTableWidget to add more icons into the particular Item ..but my application is getting crash ..plz let thro some light on this.. i am very new to this QT.
          @
          QTableWidgetItem *item;
          item[0]=QTableWidgetItem(QIcon("C:\db.ico"),"",1);
          item[1]=QTableWidgetItem(QIcon("C:\db.ico"),"",1);
          item[2]=QTableWidgetItem(QIcon("C:\db.ico"),"",1);

          QTableWidget tableWidget(1, 1);
          tableWidget->setItem(row, 0, item);
          @
          its throwing some error like..
          @
          Application.exe exited with code -1073741819
          @

          Edit: Please use @ tags around code sections; Andre

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            M_31, please wrap your code in @ tags.

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Are you sure the above even compiles? You are creating items on the stack instead of the heap, and you are setting an array where a pointer to a single item is expected (yes, I know that arrays work like pointers...). And yet you are suprised that it doesn't work?

              In a single position in a tableWidget, you can only put a single QTableWidgetItem, and that item has to be on the heap. So, putting multiple images in a single cell will have to be done differently. Basically, you have two options:

              Merge your images into a single image (for instance by painting the images on a single new QImage), or

              Create your own delegate, put the different images in different roles or in some kind of other data structure you can put in a QVariant, and let that delegate render all the images in a single cell.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                M_31
                wrote on last edited by
                #7

                it sounds good..

                Can i have any sample application site to have some idea abt this merging images into a single image or creating own delegates to put multiple images??

                Plz help me on this..

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dakron
                  wrote on last edited by
                  #8

                  Please take a look at my first entry in this thread.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    [quote author="M_31" date="1310551796"]it sounds good..
                    Can i have any sample application site to have some idea abt this merging images into a single image or creating own delegates to put multiple images??
                    [/quote]
                    I don't know of sample applications, but the documentation of [[Doc:QImage]] and [[Doc:QPainter]] are not so hard to understand. What it comes down to is:

                    Load the images you want to display into separate QImage instances

                    Calculate the size needed for an image that can contain them all

                    Create a new QImage of the size calculated in step 2, and fill it with the background color you want

                    Open a QPainter on the new image, and use an appropriate ::drawImage() overload to draw the separate images into your One-Image-To-Rule-Them-All(TM).

                    Set the newly drawn image as the image to draw in your QTableWidget cell.

                    That's only a rough outline, of course, but it should get you started I think. Give it a serious try, and if you have any questions on this that you can't figure out by reading through the docs, please do come back and ask in this topic.

                    And please: don't open a new topic on the same issue.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      M_31
                      wrote on last edited by
                      #10

                      Thanks Andre

                      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