Results 1 to 4 of 4

Thread: Fill QTableWidget and refresh it with button

  1. #1
    Join Date
    Dec 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Fill QTableWidget and refresh it with button

    Hi all!
    Guys please help me. I have QTableWidget in Dialog Window
    Qt Code:
    1. AddAgentDlg::AddAgentDlg(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(pressedB()));
    7. connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(addtextureclicked()));
    8. connect(ui.comboBox, SIGNAL(activated(const QString&)), this, SLOT(opendialog(const QString&)));
    9. connect(ui.tableWidget, SIGNAL(cellDoubleClicked(0,0)), this, SLOT(addtextureclicked()));
    10. connect(this, SIGNAL(update1()), this, SLOT(update2()));
    11. attr = ".3ds";
    12.  
    13. QDir dir("textures/");
    14. QFileInfoList dirContent = dir.entryInfoList(QStringList()<< "*.Png", QDir::Files | QDir::NoDotAndDotDot);
    15. ui.tableWidget->setColumnCount(5);
    16. ui.tableWidget->setRowCount(dirContent.size());
    17. ui.tableWidget->resizeRowsToContents();
    18. ui.tableWidget->resizeColumnsToContents();
    19. addItem->setData(Qt::DecorationRole, QPixmap("media/addItem.png").scaled(60,60));
    20. addItem->setData(Qt::ToolTipRole, QVariant("Add Texture Image"));
    21. ui.tableWidget->setItem(0,0, addItem);
    22. Q_FOREACH (QFileInfo fileInfo, dirContent)
    23. {
    24. static int row = 0, column = 1, columnNumber = 5;
    25. img->setData(Qt::DecorationRole, QPixmap(fileInfo.absoluteFilePath()).scaled(60,60));
    26. QString str_temp = fileInfo.absoluteFilePath();
    27. QString str = fileInfo.fileName();
    28. QVariant str2(str);
    29. img->setData(Qt::UserRole+1, str2 );
    30. ui.tableWidget->setItem(row,column++,img);
    31. if (column > columnNumber) {
    32. column = 0;
    33. row++;
    34. }
    35. }
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 
    Is it right? How can I make it update via pushButton? ui.tableWidget->update() nor repaint doesn't work.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fill QTableWidget and refresh it with button

    Where to you update the content?

    And check the output log of your application, it will tell you that your fourth connect is not possible.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Fill QTableWidget and refresh it with button

    I have push button that connect with this slot
    Qt Code:
    1. ui.tableWidget->clear();
    2. ui.tableWidget->setRowCount(0);
    3. ui.tableWidget->setColumnCount(0);
    4. filltable();
    To copy to clipboard, switch view to plain text mode 
    Where filltable is function to populate QTableWidget. First populate in window is perfect. But when I push button, clear data and try repopulate table this is what i get : First populate - ok CzIWxUt.png after press pushButton aBEoLd7.png it's shift images. i don't understand why
    Last edited by Doppelganger; 18th December 2014 at 14:28.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fill QTableWidget and refresh it with button

    So both times you call filltable()?

    The code you posted so far has nothing to do with filltable()

    How do you expect help if your program is doing something totally different than what you post?

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 14th March 2018, 21:25
  2. Replies: 1
    Last Post: 26th April 2012, 11:36
  3. Replies: 1
    Last Post: 21st April 2011, 10:36
  4. Replies: 2
    Last Post: 14th January 2011, 16:09
  5. QTableWidget and stop refresh
    By Darthspawn in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2010, 16:37

Tags for this Thread

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.