Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Populating table cells with various widgets

Populating table cells with various widgets

Scheduled Pinned Locked Moved Language Bindings
7 Posts 3 Posters 9.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.
  • F Offline
    F Offline
    frueter
    wrote on last edited by
    #1

    Hi everyone,

    I am just starting to learn QT (using PySide) and am wondering how I can use widgets such as ComboBox, PushButton, CheckBox etc. inside of (or as) table cells.
    I've searched high and low for examples but haven't been able to find what I need.

    Would anybody be willing to lead me in the right direction? It'd be very much appreciated!

    Thanks,
    frank

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

      Hi,

      You're in the wrong section. Your question has nothing to do with Qt Quick & QML. This is a Qt (PySide) related question. Thus, you should have asked "here":http://qt-project.org/forums/viewforum/15/

      However, if I understood correctly, you're trying to insert widgets such as QComboBox or QPushButton into a QTableView.
      What you need is a "QStyledItemDelegate":http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html.
      Juste create your own custom delegate, and override the createEditor(), setEditorData(), setModelData() and sizeHint() functions (you may have to override paint() as well).
      You can look at the "SpinBoxDelegate":http://doc.qt.nokia.com/4.7-snapshot/itemviews-spinboxdelegate.html example.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        frueter
        wrote on last edited by
        #3

        Oops, sorry about that. I misunderstood the forum description.
        Thanks heaps for the reply, I will take a look at your suggestion.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          I have moved the thread to the Language Bindings forum.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            frueter
            wrote on last edited by
            #5

            thanks.

            So I had a look at the "SpinBoxDelegate example":http://qt.gitorious.org/pyside/pyside-examples/blobs/492cb950507fc1606615c9869148baae45b33235/examples/itemviews/spinboxdelegate.py but realised that it's using the QTableView and not QTableWidget. QTableView seems to use spinbox widgets automatically anyway for numbers which confused me a bit (see below code).

            Also, in the example the entire QTableView is set to use the SpinBoxDelegate, but I need different types of widgets/delegates in the table (combo boxes, colour swatches, etc).
            I'm having a hard time finding the right information about this as every example I stumble across seems to tackle things differently.
            Any more pointers anyone? I'd be very grateful!

            Thanks,
            frank

            @import sys
            from PySide import QtCore, QtGui

            class TableTest( QtGui.QTableView ):
            def init( self ):
            super( TableTest, self ).init()

                self.model = QtGui.QStandardItemModel( 1, 3 )
                self.setModel( self.model )
            
                testFloat = 1.234
                testString = 'hello'
                testList = [ 'A', 'B', 'C' ]
            
                index = self.model.index( 0, 0, QtCore.QModelIndex() )
                self.model.setData( index, testFloat )
                index = self.model.index( 0, 1, QtCore.QModelIndex() )
                self.model.setData( index, testString )
                index = self.model.index( 0, 2, QtCore.QModelIndex() )
                self.model.setData( index, testList )
            
                        
                self.setWindowTitle( "Spin Box Delegate  - not?" )
                self.show()
            

            def main():
            app = QtGui.QApplication( sys.argv )
            tableView = TableTest()
            sys.exit(app.exec_())

            if name == "main":
            main()@

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

              bq. but realised that it’s using the QTableView and not QTableWidget.

              QTableWidget just inherits QTableView and implements a custom model (QTableModel). Anyway, for scalability reasons, the Q*Widget should only be used for static content

              bq. but I need different types of widgets/delegates in the table (combo boxes, colour swatches, etc).

              You are in charge of creating the corresponding widget for the cell. This is the QStyledItemDelegate::createEditor role.

              1 Reply Last reply
              0
              • F Offline
                F Offline
                frueter
                wrote on last edited by
                #7

                bq. for scalability reasons, the Q*Widget should only be used for static content

                you mean in this case using QTableWidget will be too slow for large tables as opposed to sub classing QTableView and building the required stuff yourself?
                Someone pointed out the QTableWidget.setCellWidget method which lets you do what I'm after very easily, but according to what you are suggesting this will become a problem?
                I'm just really trying to learn things the right way if possible so please excuse my ignorant questions

                bq. You are in charge of creating the corresponding widget for the cell. This is the QStyledItemDelegate::createEditor role.

                thanks, I will investigate that more.

                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