PDA

View Full Version : QtableWidget moving cellWidget



hubipet
22nd October 2010, 08:06
Hallo

I'm using 2 QTablewidgets which cells are filled with cellWidgets i.e QPushButton.
now I want to move those cellwidgets from one TableWidget to the other.

The cellWidgets I use look like this:




class Strip_t : public QPushButton
{
Q_OBJECT
public:
explicit Strip_t(QString, QWidget *parent = 0);

signals:

public slots:

};

#include "Strip.h"

Strip_t::Strip_t(QString _Txt, QWidget *parent) :
QPushButton(parent)
{
QPalette Pal;
QBrush Brush;
setMinimumSize(500, 20);
setMaximumSize(500, 20);
setAutoFillBackground(true);
Pal = palette();
Brush = Pal.brush(QPalette::Button);
Brush.setColor(Qt::blue);
setPalette(Pal);
setText(_Txt);
}





The constructor of my Mainwindow looks like that.




class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;

Strip_t* Strip;
Strip_t* TStrip;
};


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

Strip = new Strip_t("0", ui->tableWidget1);
ui->tableWidget1->setCellWidget(0,0,Strip);
Strip = new Strip_t("1", ui->tableWidget1);
ui->tableWidget1->setCellWidget(1,0,Strip);
Strip = new Strip_t("2", ui->tableWidget1);
ui->tableWidget1->setCellWidget(2,0,Strip);
Strip = new Strip_t("3", ui->tableWidget1);
ui->tableWidget1->setCellWidget(3,0,Strip);
Timer1Id = startTimer(1000);
std::cout << "start Timer: " << Timer1Id << std::endl;

}




Now I want to move the a cellwidget to another cell:



Strip_t* Temp = ui->tableWidget1->cellWidget(3,0);
ui->tableWidget2->setCellWidget(1,0,Temp);



that works :D

but if I try to restore it to it's former place




Strip_t* Temp = ui->tableWidget2->cellWidget(1,0);
ui->tableWidget1->setCellWidget(3,0,Temp);





the cellwidget completely disappears ?(


Any ideas or tips what's going wrong?