Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Updating QTableWidget
QtWS25 Last Chance

Updating QTableWidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doppelganger
    wrote on last edited by
    #1

    Hi all!
    Guys please help me. I have QTableWidget in Dialog Window
    @AddDlg::AddDlg(QWidget *parent)
    : QDialog(parent)
    {
    ui.setupUi(this);

    connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(pressedB()));
    connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(addtextureclicked()));
    connect(ui.comboBox, SIGNAL(activated(const QString&)), this, SLOT(opendialog(const QString&)));
    connect(ui.tableWidget, SIGNAL(cellDoubleClicked(0,0)), this, SLOT(addtextureclicked()));
    connect(this, SIGNAL(update1()), this, SLOT(update2()));
    attr = ".3ds";

    QDir dir("textures/");
    QFileInfoList dirContent = dir.entryInfoList(QStringList()<< ".Png", QDir::Files | QDir::NoDotAndDotDot);
    ui.tableWidget->setColumnCount(5);
    ui.tableWidget->setRowCount(dirContent.size());
    ui.tableWidget->resizeRowsToContents();
    ui.tableWidget->resizeColumnsToContents();
    QTableWidgetItem
    addItem = new QTableWidgetItem;
    addItem->setData(Qt::DecorationRole, QPixmap("media/addItem.png").scaled(60,60));
    addItem->setData(Qt::ToolTipRole, QVariant("Add Texture Image"));
    ui.tableWidget->setItem(0,0, addItem);
    Q_FOREACH (QFileInfo fileInfo, dirContent)
    {
    static int row = 0, column = 1, columnNumber = 5;
    QTableWidgetItem* img = new QTableWidgetItem;
    img->setData(Qt::DecorationRole, QPixmap(fileInfo.absoluteFilePath()).scaled(60,60));
    QString str_temp = fileInfo.absoluteFilePath();
    QString str = fileInfo.fileName();
    QVariant str2(str);
    img->setData(Qt::UserRole+1, str2 );
    ui.tableWidget->setItem(row,column++,img);
    if (column > columnNumber) {
    column = 0;
    row++;
    }
    }

    }@
    It fill QTableWidget that i made with images from directory. But when I copy new file in this directory I can't refresh tableWidget. Not with ui.tableWidget->update(); nor with ui.tableWidget->repaint(). I'm new with QT so can't figure it out by myself. Where did I mistaker or what am I doing wrong?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Either you would need to call again your loop to re-populate the QTableWidget (don't forget to clean first) or just add your new element at the bottom of your widget.

      Update won't help you since it triggers a repaint of the widget, but that doesn't imply refreshing the underlying data. That's done at the model level which will signal to the view that it must refresh.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Doppelganger
        wrote on last edited by
        #3

        Thank you for your answer!
        with this
        @ui.tableWidget->clear();
        ui.tableWidget->setRowCount(0);
        ui.tableWidget->setColumnCount(0);
        filltable();@
        It does update TableWidget but in weird way first population right after building is ok !http://i.imgur.com/CzIWxUt.png()!, after added new image to directory !http://i.imgur.com/aBEoLd7.png()! It doesnt display one of images and shift it from start column

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          row is a static variable. as well as column and columnNumber. By the way, why ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved