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. QTableWidget and QComboBox, issues when changing the QComboBox content

QTableWidget and QComboBox, issues when changing the QComboBox content

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.0k Views 1 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.
  • C Offline
    C Offline
    Cayan
    wrote on last edited by
    #1

    Hi there,

    I've added a QComboBox inside a QTableWidget, I need to process data every time this QComboBox content changes. There are a lot of these QComboBox in the QTableWidget.

    What I have done so far:

    • Used the QTableWidget SIGNALS, without success. Seems like they properly work only on QTableWidgetItems.
    • Tried to connect the editTextChanged SIGNAL, worked but I need to know the row of the item. When I change the content using MouseWheel for example the table's current row does not change. The content of these QComboBox may be the same, so I can't search.
    • Tried to install the event filter, but none seems to work when I confirm a new index for the QComboBox.
    • Added a property to each of these dynamic items with their row position, helped on the event filter, but I had to disable the ordination system.

    I'll try to sync all of what I've done to make it work.
    Does anyone know a better way to do this?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      How did you add the combo boxes? Did you use the setTableWidget?

      I would prefer using a QStyledItemDelegate subclass and use custom editors there (e.g. a combo box). That means, if you edit the table, a combo box appears in the edited cell and you can change the values.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Cayan
        wrote on last edited by
        #3

        I used setCellWidget.
        What is this setTableWidget? I couldn't find any reference for it. (with a fast google search)

        I haven't used this class QStyledItemDelegate yet, your idea sounds interesting. Is there any example that you could show me?

        A temporary solution that I've managed is to use setCurrentCell when the QEvent::FocusIn event is filtered.

        Thanks for your answer!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          [quote author="Cayan" date="1314648789"]I used setCellWidget.
          What is this setTableWidget? I couldn't find any reference for it. (with a fast google search)
          [/quote]

          Sorry, I meant setCellWidget :-)

          [quote author="Cayan" date="1314648789"]I haven't used this class QStyledItemDelegate yet, your idea sounds interesting. Is there any example that you could show me?[/quote]

          You can have a look at the "description of Model-View":http://doc.qt.nokia.com/4.7/model-view-programming.html#delegate-classes or at the "examples of Model-View":http://doc.qt.nokia.com/4.7/examples-itemviews.html or the "SpinBox Delegate example":http://doc.qt.nokia.com/4.7/itemviews-spinboxdelegate.html

          The examples always use a view class but the QTableWidget is a derived class of QTableView, so the delegates will also work there

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            [quote author="Cayan" date="1314648789"]I used setCellWidget.
            What is this setTableWidget? I couldn't find any reference for it. (with a fast google search)[/quote]

            In this case you create a QComboBox, so I'd just connect a signal of that combobox to some slot.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Cayan
              wrote on last edited by
              #6

              I tried to use the Model View system to make it work, but it gave me more headaches than solutions.
              QTableView::setModel is private so I couldn't make it work with the table I had.

              Now it is working, what I've done? Filtered the QEvent::FocusIn to force the Cell selection, here goes the code:

              @bool Dialog::eventFilter(QObject object, QEvent event)
              {
              if(object->isWidgetType() && event->type() == QEvent::FocusIn)
              {
              QWidget
              widget = qobject_cast<QWidget
              >(object);
              if(widget)
              {
              ui->table->setCurrentCell(widget->pos().y() / 30, 0);
              }
              }

              return false;
              

              }@

              I'm using that stupid way to select the cell because it was not working with "the proper way". The cells height are constant so a temporary solution for a short on time project.

              I'm glad this is working, but I found what I've considered an error, maybe from Qt.
              I created a topic to discuss it: "link":http://developer.qt.nokia.com/forums/viewthread/9323/.

              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