Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QTableView readonly columns....
Qt 6.11 is out! See what's new in the release blog

QTableView readonly columns....

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 6 Posters 10.2k 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.
  • J Offline
    J Offline
    jammulak
    wrote on last edited by
    #1

    Hi ,

    I am developing an enterprise application using NokiaQT SDK. I have used Sqlite DB and Qtableview for showing data in forms and to edit tha data via UI. My problem is I want to make one or two columns readonly.

    Can you please give solution with out subclassing QTableView because I have derived class from QWidget and using QTableview as a member.

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      have a look at

      @setItemDelegateForColumn ( int column, QAbstractItemDelegate * delegate )@

      You will need a readonly delegate. There is an example on how to do this :

      read the whitepaper "Qt 4's Model/View Delegates"

      You will find the link to download "here":http://www.qtrac.eu/marksummerfield.html

      Have fun

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dialingo
        wrote on last edited by
        #3

        No need to use a delegate.
        reimplement
        @Qt::ItemFlags QAbstractItemModel::flags ( const QModelIndex & index ) const@

        This way you can specify for each cell the properties, like editable, dragable ...

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          The flags method is the one to use.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

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

            Indeed, use the flags method. You can either do that by subclassing the actual model, or by using a proxy model that just overrides the flags method to return the correct flags. There is an, perhaps already usuable, "example":http://developer.qt.nokia.com/wiki/QSortFilterProxyModel_subclass_for_readonly_columns_columns_with_checkboxes_and_password_columns on how to do this on the wiki. The class presented there can already make columns read only.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              derf_r
              wrote on last edited by
              #6

              Hello

              For my use, the Eddy's solution is better.
              In the example there is 2 classes, I use only only one.

              Thank you very much

              Frederic

              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