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. Add square in table widget
Forum Update on Monday, May 27th 2025

Add square in table widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 801 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.
  • B Offline
    B Offline
    Ballaz995
    wrote on last edited by aha_1980
    #1

    Hi guys,
    I have a table widget with 3 rows and 5 columns and I wanna add in the first column of any row a simple green square.
    I don t want add an external png, how I can do it?

    for (int j = 0; i < var.size(); ++j)
        ui->tableWidget->setItem(j, 0, new ??? );
    
    K 1 Reply Last reply
    0
    • B Ballaz995

      Hi guys,
      I have a table widget with 3 rows and 5 columns and I wanna add in the first column of any row a simple green square.
      I don t want add an external png, how I can do it?

      for (int j = 0; i < var.size(); ++j)
          ui->tableWidget->setItem(j, 0, new ??? );
      
      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Ballaz995

      You generate QImage with setColor tranform with QPixmap::fromImage for instance.

      Vote the answer(s) that helped you to solve your issue(s)

      B 1 Reply Last reply
      2
      • K koahnig

        @Ballaz995

        You generate QImage with setColor tranform with QPixmap::fromImage for instance.

        B Offline
        B Offline
        Ballaz995
        wrote on last edited by
        #3

        @koahnig
        I don't understand how can i generate the square

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4
          auto model = ui->tableWidget->model();
          QPixmap greenSquare(20,20);
          greenSquare.fill(Qt::green);
          for(int i=0, maxRow = model ->rowCount();i<maxRow ;++i)
          model->setData(model->index(i,0),greenSquare,Qt::DecorationRole);
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          4

          • Login

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