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. How to update a table's combox's display effectively??
Forum Updated to NodeBB v4.3 + New Features

How to update a table's combox's display effectively??

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 434 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.
  • A Offline
    A Offline
    ailika
    wrote on last edited by
    #1

    I have created a QTableWidget and used a delegate and QModel to contain some combobox, and the combobox works.
    But there are limitation between columns. For example, if I change the data in column 1, the data in column 2 will change with it. Note: column 1 and 2 are both comboxs.
    So when I change the data in column1, I will change the data in column 2 in the function setData() of the model class. After change data, I emit a dataChanged(index, index, {role});
    But the result is not satisfatory. Column 2's data do not change immediately, it won't change untill I click the mouse or I minimize the window and restore the window.
    I have tried the update() funtion and it didn't work.
    I guess when I change column 1's combobox, it has the focus or something that stops the table painting the new data.
    What must I do to get it work correctly?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since you're using item widgets you have to connect to dataChanged() and call update() for the corresponding combobox by yourself.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • A Offline
        A Offline
        ailika
        wrote on last edited by
        #3

        I have tried to call the table's update() immediately after setDate, but it did'nt work?
        You mean I should connect dataChanged() to updata(), not just emit it?
        Which update() I should connect dataChanged() to? combobox's update()?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How do you fill the data of your comboboxes? Not via the model.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ailika
            wrote on last edited by
            #5

            I fill the combobox in the createEditor function of the delegate, such as:

                QComboBox *cb = new QComboBox(parent);
                cb->addItem(QString("Low"));
                cb->addItem(QString("High"));
                return cb;
            
            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              I will change the data in column 2 in the function setData() of the model class. After change data, I emit a dataChanged(index, index, {role});

              Could you show this part of the code?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              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