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. QTableView QCheckBox QComboBox
Forum Updated to NodeBB v4.3 + New Features

QTableView QCheckBox QComboBox

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 4.3k 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.
  • P Offline
    P Offline
    pmjz
    wrote on last edited by
    #1

    How can I

    display QCheckBox in the first Column of the QTableView, and QComboBox in several other columns.

    get the signal from those QCheckBox and QComboBoxes

    Thanks in advance

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Views display checkboxes if the model has the userCheckable flag set, and the model returns valid data for the Qt::CheckStateRole.

      To use a combo box as your editor, you will need to set an appropriate QItemDelegate subclass that creates a combobox as the editor widget.

      The model will give you a generic dataChanged() signal if the data is modified. Depending your your model, you may get more specific signals from there.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pmjz
        wrote on last edited by
        #3

        thanks a lot, if the users edit,check or select any item from the GUI, can that dataChanged() signal be emit automatically? In my perspective, model is different with view.

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

          If you create your own custom model, YOU must take care of signals like dataChanged etc.
          To get more info on that, read "an editable model":http://doc.qt.nokia.com/4.7/model-view-programming.html#an-editable-model

          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
          • P Offline
            P Offline
            pmjz
            wrote on last edited by
            #5

            QComboBoxes has already been displayed, but only double click the cells, the comboboxes will appear, I want those comboboxes appear as the tableview is displayed, how can I do for that, thanks in advance

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              That is how delegates work. You can set a widget for a table cell using setCellWidget, but it will not be very performant for larger data sets, and it goes against the grain of model view programming a bit.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                octal
                wrote on last edited by
                #7

                Yes, the editor is created when the user starts editing the cell.

                If you want your QComboBox to appear all the time, I guess you'll have to reimplement the paint method of your delegate and draw the QComboBox by yourself. See "QStyle::drawComplexControl":http://doc.qt.nokia.com/latest/qstyle.html#drawComplexControl

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

                  There's a wiki article "Combo Boxes in Item Views":http://developer.qt.nokia.com/wiki/Combo_Boxes_in_Item_Views that shows you how to create a [[Doc:QStyledItemDelegate]] subclass for that task.

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

                  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