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. TableWidget text changed

TableWidget text changed

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.6k 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.
  • W Offline
    W Offline
    Wuzi
    wrote on last edited by
    #1

    Hi,

    I'm trying to make a programm where I can add dynamicaly new pads and set properties. The pad name should be showed in a ListView, and the Properties of every pad should be showed in a TableWidget.
    In a new Dialog I can type in names and then they will added to the ListWidget. The Names are connected with random properties(only to test it). Every time I click on a name in the ListWidget, in the TableWidgets will be shown the properties of this name. Now my Problem: I would make, that when I change the name or a property in the TableWidget it should change the new property in the list where I save the data. I didn't find a function which send a signal, when a text in the TableWidget changes. If I get the name I can search the name in the list and change the property.

    Is that the right way or should I save the name with properties in an sql database?

    Here you see my implementation of creating a new pad:
    void MainWindow::set_pad_name(QString value)
    {
    Pad pad;
    pad.name = value;
    pad.height = QString::number(rand());
    pad.width = QString::number(rand());;
    pad.pos_x = QString::number(rand());;
    pad.pos_y = QString::number(rand());;
    list->append(pad);
    listWidget_pads_name->addItem(value);
    }

    W 1 Reply Last reply
    0
    • W Wuzi

      Hi,

      I'm trying to make a programm where I can add dynamicaly new pads and set properties. The pad name should be showed in a ListView, and the Properties of every pad should be showed in a TableWidget.
      In a new Dialog I can type in names and then they will added to the ListWidget. The Names are connected with random properties(only to test it). Every time I click on a name in the ListWidget, in the TableWidgets will be shown the properties of this name. Now my Problem: I would make, that when I change the name or a property in the TableWidget it should change the new property in the list where I save the data. I didn't find a function which send a signal, when a text in the TableWidget changes. If I get the name I can search the name in the list and change the property.

      Is that the right way or should I save the name with properties in an sql database?

      Here you see my implementation of creating a new pad:
      void MainWindow::set_pad_name(QString value)
      {
      Pad pad;
      pad.name = value;
      pad.height = QString::number(rand());
      pad.width = QString::number(rand());;
      pad.pos_x = QString::number(rand());;
      pad.pos_y = QString::number(rand());;
      list->append(pad);
      listWidget_pads_name->addItem(value);
      }

      W Offline
      W Offline
      Wuzi
      wrote on last edited by
      #2

      I found this function:
      void MainWindow::on_tableWidget_properties_itemChanged(QTableWidgetItem *item)
      {
      if(item != NULL)
      {
      QListWidgetItem *item = new QListWidgetItem;
      item = listWidget_pads_name->currentItem();
      item->setText(item->text());
      }
      }

      but every time I would compile it, the program crash without an error.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jalomic
        wrote on last edited by
        #3

        I think you need to use MVC paradigm.
        http://doc.qt.io/qt-4.8/model-view-programming.html Read this ! You need one data source for two views

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          You are using the same item variable everywhere. That might be the source of your crash. itemChanged(...) signal gives which item has been changed on tableWidget. From this you can text(...). This you can set anywhere you want.

          1. Why are you creating the QListWidgetItem object again
          2. Why you are naming every variable as item only.
          3. Check the return value of current item().. It may be null as as well.

          If you can give us the sample of your program we can help you better.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          4
          • W Offline
            W Offline
            Wuzi
            wrote on last edited by Wuzi
            #5

            Thank you for your reply.

            Here you can find my code:
            https://drive.google.com/file/d/0B_vrp_7db9bBVGlRWnZiYXRQMUU/view?usp=sharing

            If you have some other improvements I would like to hear these :)

            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