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. Store content of QTableWidget into a buffer variable
Forum Updated to NodeBB v4.3 + New Features

Store content of QTableWidget into a buffer variable

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.5k Views 2 Watching
  • 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.
  • KampiK Offline
    KampiK Offline
    Kampi
    wrote on last edited by
    #1

    Hello,

    I have a configuration window with a table to add some filter options. A user can add more filter with an "Add" Button to the table. The filter rules getting stored after the user pressed a "OK" button. If the user close the window without pressing "OK" the new input should be discarded.
    The current implementation doesn´t discard the new input after closing the window. My idea is to store the table into a buffer when the user is pressing the "OK" buffer and load this buffer when the user open the configuration window again.

    I write this method to store the current table to the buffer:

    void Filter::saveTable( void )
    {
        tableBuffer->setRowCount(ui->tableWidget->rowCount());
        tableBuffer->setColumnCount(ui->tableWidget->columnCount());
    
        for(int i_Row = 0; i_Row < ui->tableWidget->rowCount(); i_Row++)
        {
            for(int i_Column = 0; i_Column < ui->tableWidget->colorCount(); i_Column++)
            {
                QTableWidgetItem* Item = ui->tableWidget->item(i_Row, i_Column);
    
                tableBuffer->setItem(i_Row, i_Column, Item);
            }
        }
    }
    
    

    I got this message when I try to save the current table from the ui into the buffer:

    QPaintDevice::metrics: Device has no metric information

    What is the problem? Does Qt support a better solution to discard changes in a table when the table window got closed without pressing "OK"?

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

      Hi
      Are you sure
      "QPaintDevice::metrics: Device has no metric information"
      comes from this code?

      Also,
      QTableWidgetItem* Item = ui->tableWidget->item(i_Row, i_Column);
      tableBuffer->setItem(i_Row, i_Column, Item);

      So u take the item from one TableWidget and insert into another table?

      Im not sure it works as we think as then its shared between 2 widgets?
      So both will try to delete it?

      • Does Qt support a better solution to discard changes in a table

      Well not pr automatic, but normally you would have data (the filters) in its own class/list.
      Then when open the Editor, load data to the table
      If user dont press ok, simply not save table back to master data list.

      1 Reply Last reply
      1
      • KampiK Offline
        KampiK Offline
        Kampi
        wrote on last edited by
        #3

        Hello

        yes I´m sure, because I doesn´t get this message anymore after removing this lines.
        Reloading the data is a better idea I think. Thank you for this hint. I think I will solve it in this way.

        mrjjM 1 Reply Last reply
        0
        • KampiK Kampi

          Hello

          yes I´m sure, because I doesn´t get this message anymore after removing this lines.
          Reloading the data is a better idea I think. Thank you for this hint. I think I will solve it in this way.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kampi
          Hi
          ok. its just it sound like something with painting and all you
          do is adding items. But must be indirectly then.
          seems to come from qpaintdevice.cpp
          ifndef Q_WS_QPA
          int QPaintDevice::metric(PaintDeviceMetric) const
          {
          qWarning("QPaintDevice::metrics: Device has no metric information");
          return 0;
          }
          #endif

          So seems its simply not compiled in?

          Anyway, hopefully it will go away with your new design :)

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Ivan Kosik
            wrote on last edited by
            #5

            @Kampi
            Hello,
            You have a typo in this line:

            for(int i_Column = 0; i_Column < ui->tableWidget->colorCount(); i_Column++)
            

            Change colorCount() to columnCount()

            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