PDA

View Full Version : QTableWidget -> QDockWidget,



ogre
25th January 2006, 15:59
Hello,

i try to put a QTableWidget in a QDockWidget, but I don’t know what I have to do.

Can everyone help me?

My Code:


void MainWindow::createDockWindows()
{
// first Docker
QDockWidget *dock = new QDockWidget(tr("Text"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
customerList = new QListWidget(dock);
customerList->addItems(QStringList() << "Hier soll was stehen");
dock->setWidget(customerList);
dock->setMaximumWidth( 230 );
addDockWidget(Qt::RightDockWidgetArea, dock);

/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// The Table
QStringList headerLables1;
headerLables1 << "Name"
<< "Key";

tableWidget1 = new QTableWidget();
tableWidget1->setRowCount( 10 );
tableWidget1->setColumnCount( headerLables1.count() );
tableWidget1->setHorizontalHeaderLabels( headerLables1 );

QTableWidgetItem *nameCell = new QTableWidgetItem( "name" );
QTableWidgetItem *keyCell = new QTableWidgetItem( "key" );

tableWidget1->setItem(0,0,nameCell);
tableWidget1->setItem(1,1,keyCell);

tableWidget1->setItem(2,0,nameCell);
tableWidget1->setItem(3,1,keyCell);


/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////////////////////////////////////////


// second Docker
dock = new QDockWidget(tr("Tabelle"), this);
// insert the table here :confused:

?
.
.
.
?





thx

chombium
25th January 2006, 19:16
I think you have to set the dock widget as parent of the table.

whick means:

create the table

tableWidget1 = new QTableWidget(dock);

check the example at trolls

http://doc.trolltech.com/4.1/mainwindows-dockwidgets.html

GREETZ, chombium

axeljaeger
25th January 2006, 22:51
I think you miss a:

http://doc.trolltech.com/4.1/qdockwidget.html#setWidget

ogre
26th January 2006, 07:51
Hello,

I try setWidget(), and it’s work. But there is one another Problem.
If i put:


tableWidget1->setItem(0,0,nameCell);
tableWidget1->setItem(1,1,keyCell);

it works, but if I fill two rows:


tableWidget1->setItem(0,0,nameCell);
tableWidget1->setItem(1,1,keyCell);

tableWidget1->setItem(2,0,nameCell);
tableWidget1->setItem(3,1,keyCell);

the prog fuckt up if I close that.



QStringList headerLables1;
headerLables1 << "Name"<< "Key";

tableWidget1 = new QTableWidget();
tableWidget1->setRowCount( 10 );
tableWidget1->setColumnCount( headerLables1.count() );
tableWidget1->setHorizontalHeaderLabels( headerLables1 );

QTableWidgetItem *nameCell = new QTableWidgetItem( "name" );
QTableWidgetItem *keyCell = new QTableWidgetItem( "key" );

tableWidget1->setItem(0,0,nameCell);
tableWidget1->setItem(1,1,keyCell);

//tableWidget1->setItem(2,0,nameCell);
//tableWidget1->setItem(3,1,keyCell);



dock = new QDockWidget(tr("Koordinaten"), this);
dock->setMaximumWidth( 350 );
dock->setWidget( tableWidget1 );
addDockWidget(Qt::RightDockWidgetArea, dock);

//////////////////////////////
There is a Problem in QTableWidget.cpp. But i don't know what it’s mean.


void QTableModel::clear()
{
for (int i = 0; i < table.count(); ++i) {
if (table.at(i)) {
table.at(i)->model = 0;
delete table.at(i); <---- that’s the problem
table[i] = 0;
}
}