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. hide cell from tablewidget
Forum Updated to NodeBB v4.3 + New Features

hide cell from tablewidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 667 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.
  • NevezN Offline
    NevezN Offline
    Nevez
    wrote on last edited by
    #1

    hello,
    I wanna hide specific cells from qtablewidget. But its not working
    that code :

    tablewidget->cellWidget(rowindex,colindex)->hide();    // it crashes
    

    is there any other way i can do this?

    JonBJ 1 Reply Last reply
    0
    • NevezN Nevez

      hello,
      I wanna hide specific cells from qtablewidget. But its not working
      that code :

      tablewidget->cellWidget(rowindex,colindex)->hide();    // it crashes
      

      is there any other way i can do this?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Nevez said in hide cell from tablewidget:

      // it crashes

      Q_ASSERT(tablewidget->item(rowindex,colindex));
      Q_ASSERT(tablewidget->cellWidget(rowindex,colindex));
      

      I imagine this will fail. I suspect you have not put a widget into tablewidget->item(rowindex,colindex) --- either it has nothing in it, or it does not have a QWidget.

      1 Reply Last reply
      1
      • NevezN Offline
        NevezN Offline
        Nevez
        wrote on last edited by
        #3

        @JonB said in hide cell from tablewidget:

        Q_ASSERT(tablewidget->item(rowindex,colindex));
        Q_ASSERT(tablewidget->cellWidget(rowindex,colindex));

        Q_ASSERT(tablewidget->cellWidget(rowindex,colindex));
        

        it gives error here.

        so how can i hide custom indexed cells in tablewidget without adding widgets ?

        JonBJ 1 Reply Last reply
        0
        • NevezN Nevez

          @JonB said in hide cell from tablewidget:

          Q_ASSERT(tablewidget->item(rowindex,colindex));
          Q_ASSERT(tablewidget->cellWidget(rowindex,colindex));

          Q_ASSERT(tablewidget->cellWidget(rowindex,colindex));
          

          it gives error here.

          so how can i hide custom indexed cells in tablewidget without adding widgets ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Nevez
          What is a "custom indexed" cell?

          So since you have not done any tablewidget->setCellWidget(rowindex,colindex,widget) there is no widget in the cell and cellWidget(rowindex,colindex) will never be right.

          So what do you have in the cell, and what exactly do you mean by "hide"? It has a QTableWidgetItem just showing some text. You might blank out the text. There is no direct call to "hide" a QTableWidgetItem. According to https://forum.qt.io/topic/90416/how-to-hide-cellwidget-of-qtablewidget/6 you would have to override QTableWidget::paintEvent() and do your "hiding" there during the painting. Or there is an approach with a QStyledItemDeletegate in https://stackoverflow.com/questions/59645024/how-to-manage-visibility-of-data-in-pyqt5-qtablewidgetitem.

          1 Reply Last reply
          3
          • NevezN Offline
            NevezN Offline
            Nevez
            wrote on last edited by
            #5

            thanks for the answer. For now, I continued by deleting the text in the item.
            because if I try to add widgets the process will become very heavy and take long time.

            I also added a button to the cells with the paint function using qstyleditemdelegate. But this overlapped with the text.
            How can I solve this?
            7fa7e30c-7248-41e0-95d7-06d7e0ce05d0-image.png

            JonBJ 1 Reply Last reply
            0
            • NevezN Nevez

              thanks for the answer. For now, I continued by deleting the text in the item.
              because if I try to add widgets the process will become very heavy and take long time.

              I also added a button to the cells with the paint function using qstyleditemdelegate. But this overlapped with the text.
              How can I solve this?
              7fa7e30c-7248-41e0-95d7-06d7e0ce05d0-image.png

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Nevez said in hide cell from tablewidget:

              because if I try to add widgets the process will become very heavy and take long time.

              Indeed!

              I also added a button to the cells with the paint function using qstyleditemdelegate. But this overlapped with the text.

              QStyledItemDelegate::paint() says

              Whenever possible, use the option while painting. Especially its rect variable to decide where to draw

              So on entry option.rect states the whole cell's rectangle to draw into. If you put something like a button into that area you need to change the rectangle to exclude the area it occupies so that what you pass onto the default painter method for the text is only passed the remaining unoccupied area.

              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