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 wrap a QTableWidget?

How to wrap a QTableWidget?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k 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.
  • S Offline
    S Offline
    shaabaadoo
    wrote on last edited by
    #1

    Hi all,

    I have a QTableWidget with three columns and any number of rows, e.g. four rows:

    index(0,0) index(0,1) index(0,2)
    index(1,0) index(1,1) index(1,2)
    index(2,0) index(2,1) index(2,2)
    index(3,0) index(3,1) index(3,2)

    Unfortunatelly the table is nested in a widget which height is less than the height of the table and I have to avoid scrollbars.
    Therefore I need to wrap the table after few rows and paint the rest of the table next to it:

    index(0,0) index(0,1) index(0,2) index(2,0) index(2,1) index(2,2)
    index(1,0) index(1,1) index(1,2) index(3,0) index(3,1) index(3,2)

    How can I do that?
    It is possible to move cells in the paintEvent()?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I haven't done it so it's just a wild idea but you could add a proxy model between your table view and model. That proxy model would then be in charge to redo the geometry (more or less columns and rows so nothing directly gui) of your model to accomodate the new size of your QTableView

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shaabaadoo
        wrote on last edited by
        #3

        Thanks for your reply!

        Actually I do not want to create a table with 6 columns and 2 rows.

        The rows are of different heights. Creating a table with 6 columns will result in same height for row0 and row2 ... and row1 and row3.

        Is there a possibility to move the position of the cell-rect? Maybe somewhere in the paint() method ... So I would set the position of row2 and row3 next to the other rows.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shaabaadoo
          wrote on last edited by
          #4

          To change the position of a cell I have overwritten the paint() method of the ItemDelegate class:

          @class MyDelegate: public QStyledItemDelegate
          {
          public:
          MyDelegate( QObject* object = 0 )
          : QStyledItemDelegate(object)
          {};

          void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
          {
          QStyleOptionViewItem opt = option;
          initStyleOption( &opt, index );

            // move all rows except the first one
            if( index.row() != 1 )
               opt.rect.translate( 50,50);
          
            QStyledItemDelegate::paint( painter, opt , index );
          

          }
          };@

          I initialized the ItemDelegate in the constructor of my QTableWidget:

          @setItemDelegate( new MyDelegate() );@

          But nothing happens ...

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            The delegate is responsible to paint the cell but not its position.

            Have a look at the "TiledItemView":http://www.informit.com/articles/article.aspx?p=1613548 from Mark Summerfield (the book is worth buying)
            It should help you get started

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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