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. QTableWidget + setCellWidget(myWidget) how remove from Cell without delete myWidget ?

QTableWidget + setCellWidget(myWidget) how remove from Cell without delete myWidget ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 6.5k 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.
  • pdn_mailP Offline
    pdn_mailP Offline
    pdn_mail
    wrote on last edited by
    #1

    Hi!
    I insert single myWidget to QTableWidget by setCellWidget().
    When I using removeCellWidget() function myWidget is removed for ever, but it still will be necessary to me repeatedly.
    How correctly remove from Cell myWidget without delete myWidget?

    RatzzR raven-worxR 2 Replies Last reply
    0
    • pdn_mailP pdn_mail

      Hi!
      I insert single myWidget to QTableWidget by setCellWidget().
      When I using removeCellWidget() function myWidget is removed for ever, but it still will be necessary to me repeatedly.
      How correctly remove from Cell myWidget without delete myWidget?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @pdn_mail
      Hi,
      You may try http://doc.qt.io/qt-4.8/qtablewidget.html#takeItem

      --Alles ist gut.

      1 Reply Last reply
      1
      • pdn_mailP Offline
        pdn_mailP Offline
        pdn_mail
        wrote on last edited by
        #3

        it hardly, takeItem works with QTableWidgetItem, but not with QWidget. Different mechanisms.

        1 Reply Last reply
        0
        • pdn_mailP pdn_mail

          Hi!
          I insert single myWidget to QTableWidget by setCellWidget().
          When I using removeCellWidget() function myWidget is removed for ever, but it still will be necessary to me repeatedly.
          How correctly remove from Cell myWidget without delete myWidget?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @pdn_mail
          There is no way - currently.
          The index widget will be deleted whenever a new index widget is set.
          removeCellWidget() simply sets a NULL-widget. So you have implicitly the same problem.

          What exactly is your usecase?

          An alternative would be to add a container widget. for example: QStackedWidget
          And add the widgets there, so Qt doesn't delete them.

          if( QStackedWidget* w = qobject_cast<QStackedWidget*>( tableWidget->cellWidget(r,c) )
          {
               w->addWidget( ... )  // set widget
               w->removeWidget( ... );  //remove widget
               w->setCurrentIndex( ... ) / w->setCurrentWidget( ... );  //switch widgets
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • pdn_mailP Offline
            pdn_mailP Offline
            pdn_mail
            wrote on last edited by pdn_mail
            #5

            Thanks. But unfortunately I have other usecase, I shouldn't replace widgets in a cell, I should return to a cell initial properties which were to setCellWidget.

            void MainWindow::on_tableWidget_cellEntered(int row, int column)
            {
            QStackedWidget *sw=new QStackedWidget;
            int r=cellwidgetcoord.row; 
            int c=cellwidgetcoord.column;
            cellwidgetcoord.row=row; 
            cellwidgetcoord.column=column;
            ui->tableWidget->removeCellWidget(r,c);
            sw->addWidget(&comboBox_5);
            ui->tableWidget->setCellWidget(row, column, sw);
            }
            
            raven-worxR 1 Reply Last reply
            0
            • pdn_mailP pdn_mail

              Thanks. But unfortunately I have other usecase, I shouldn't replace widgets in a cell, I should return to a cell initial properties which were to setCellWidget.

              void MainWindow::on_tableWidget_cellEntered(int row, int column)
              {
              QStackedWidget *sw=new QStackedWidget;
              int r=cellwidgetcoord.row; 
              int c=cellwidgetcoord.column;
              cellwidgetcoord.row=row; 
              cellwidgetcoord.column=column;
              ui->tableWidget->removeCellWidget(r,c);
              sw->addWidget(&comboBox_5);
              ui->tableWidget->setCellWidget(row, column, sw);
              }
              
              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @pdn_mail
              maybe it's enough to simply hide it

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              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