Results 1 to 11 of 11

Thread: QTableWidget fails to display column/row content correctly after MainWindow resize.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableWidget fails to display column/row content correctly after MainWindow resiz

    Would you mind trying your self? The entire code for QDragDropWidget is in my previous post. So just place QTableWidget in resizable layout and promote it to QDDW. I'm interested to see of anyone else has this issue.
    No, because I am trying to get you to understand that the problem is not in your widget, it is how you are populating the widget with items after you have dropped something. Fine, you are populating a QStringList. You can't build the contents of a QTableWidget by passing in a QStringList, you have to create QTableWidgetItem instances and add each one to the table.

    I have asked you to show how you are doing that, because that is very likely where your error lies. Especially since you now say it happens both with and without D&D. The finger isn't pointing at your widget, it is pointing at how you are using the widget.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Oct 2020
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableWidget fails to display column/row content correctly after MainWindow resiz

    This is the function that populates the list:


    Qt Code:
    1. void MainWindow::DropToPlayList(QStringList list, int row) // row is the location of the row where the files are dropped
    2. {
    3. if (row < 0)
    4. row = 0;
    5.  
    6. for (int c=0;c<list.count();c++)
    7. {
    8. ui.tablePlaylist->insertRow(row+c);
    9.  
    10. // create all items for the row
    11. uint32_t duration = 0;
    12. for (int i=0;i<ui.tablePlaylist->columnCount();i++)
    13. {
    14. ui.tablePlaylist->setItem(row+c,i, new QTableWidgetItem("")); // create all column items for row
    15. }
    16.  
    17.  
    18. ui.tablePlaylist->item(row+c,COLUMN_START_TIME)->setText("00:00:00:00");
    19. ui.tablePlaylist->item(row+c,COLUMN_DURATION)->setText("duration");
    20. ui.tablePlaylist->item(row+c,COLUMN_TITLE)->setText("title");
    21. ui.tablePlaylist->item(row+c,COLUMN_LOCATION)->setText("location");
    22. ui.tablePlaylist->item(row+c,COLUMN_CATEGORY)->setText("category");
    23.  
    24. }
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2020
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableWidget fails to display column/row content correctly after MainWindow resiz

    Solution:

    QTableWidget::resizeEvent(event);

    instead of QWidget::resizeEvent(event);

  4. The following user says thank you to Milo47 for this useful post:

    d_stranz (27th October 2020)

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableWidget fails to display column/row content correctly after MainWindow resiz

    Solution:

    QTableWidget::resizeEvent(event);

    instead of QWidget::resizeEvent(event);
    Ah. Sometimes you don't notice the obvious things until they punch you in the nose. Thanks for posting your solution.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 15
    Last Post: 29th January 2020, 14:52
  2. Replies: 1
    Last Post: 20th November 2015, 09:12
  3. QListWidget: Resize to it's content
    By Fred in forum Qt Programming
    Replies: 4
    Last Post: 8th July 2014, 11:01
  4. Widget does not resize correctly
    By Demandred in forum Newbie
    Replies: 4
    Last Post: 16th April 2010, 12:06
  5. Replies: 4
    Last Post: 23rd September 2008, 12:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.