Results 1 to 4 of 4

Thread: Dynamically sized QTableWidget

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Red face Dynamically sized QTableWidget

    hey there just wondering if there is a way to createa dynamically sized QTableWidget?? depending on user input...

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Dynamically sized QTableWidget

    Quote Originally Posted by therealjag
    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..

  3. The following user says thank you to jpn for this useful post:

    therealjag (11th March 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically sized QTableWidget

    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:

    Qt Code:
    1. void DemandsTab::changeSize(QTableWidgetItem *items)
    2. {
    3. int tableSize = 0;
    4. QLabel *integerLabel = new QLabel(this);
    5. bool ok;
    6.  
    7. tableSize = QInputDialog::getInteger(this, tr("Input box"),
    8. tr("Please enter number of nodes needed for network demands:"), 25, 0, 100, 1, &ok);
    9.  
    10. if(ok)
    11. integerLabel->setText(tr("%1").arg(tableSize));
    12.  
    13. demands->setRowCount(tableSize);
    14. demands->setColumnCount(tableSize);
    15. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Dynamically sized QTableWidget

    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..
    Qt Code:
    1. bool ok = false;
    2. tableSize = QInputDialog::getInteger(...);
    3. if(ok)
    4. {
    5. demands->setRowCount(tableSize);
    6. demands->setColumnCount(tableSize);
    7. }
    To copy to clipboard, switch view to plain text mode 

    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..
    Last edited by jpn; 31st March 2006 at 21:09.

  6. The following user says thank you to jpn for this useful post:

    therealjag (1st April 2006)

Similar Threads

  1. How to make headers fixed sized? (QTableWidget)
    By macias in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2007, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.