PDA

View Full Version : Dynamically sized QTableWidget



therealjag
11th March 2006, 14:56
hey there just wondering if there is a way to createa dynamically sized QTableWidget?? depending on user input...

jpn
11th March 2006, 15:02
hey there just wondering if there is a way to createa dynamically sized QTableWidget?? depending on user input...
You mean changing the row/column count? Yes it is possible whenever you want..

therealjag
31st March 2006, 20:05
hey there i tried putting in a seperate method as a slot to change the sze of the table but sometimes when i change the size, the program crashes - does anyone know why this happens? it only happens sometimes aswell and other times it works fine... heres my code for the slot below:



void DemandsTab::changeSize(QTableWidgetItem *items)
{
int tableSize = 0;
QLabel *integerLabel = new QLabel(this);
bool ok;

tableSize = QInputDialog::getInteger(this, tr("Input box"),
tr("Please enter number of nodes needed for network demands:"), 25, 0, 100, 1, &ok);

if(ok)
integerLabel->setText(tr("%1").arg(tableSize));

demands->setRowCount(tableSize);
demands->setColumnCount(tableSize);
}

jpn
31st March 2006, 21:06
Hmm, I can't see a problem there which could cause a crash..

You still should check the value if ok was even pressed, though, and only change the size when appropriate..


bool ok = false;
tableSize = QInputDialog::getInteger(...);
if(ok)
{
demands->setRowCount(tableSize);
demands->setColumnCount(tableSize);
}


But anyway, that's not causing a crash. You seem to be forcing the integer value between 0-100, which is ok, and QTableWidget has a check for negative values so that's not the case either.. So I can't say..
Maybe the problem lies somewhere else?

Edit: Erm... what's that label doing there? I see it's adapted from the example piece of code in docs.. :) But you are allocating a new label each time the size is changed. Instantiate the label somewhere else, and only change it's value here..