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. Creating a calendar using QTableWidget with QItemDelegate
QtWS25 Last Chance

Creating a calendar using QTableWidget with QItemDelegate

Scheduled Pinned Locked Moved General and Desktop
qtablewidgetqitemdelegate
20 Posts 2 Posters 7.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.
  • B Offline
    B Offline
    Binary91
    wrote on last edited by Binary91
    #11

    yeah I know, I catched the coordinates of option.rect for the 5 cells with qDebug:
    x is alway 185, y = index.row * 51, width is always 91 and height is always 50.

    Hence, the following two methods do exactly the same positioning (I tested it):
    [code]
    painter->drawText(option.rect, "TestString");
    [/code]

    [code]
    painter->drawText(QRect(185,index.row()*51,91,50), "TestString");
    [/code]

    BUT the difference is, that the first example stores the strings INTO the cells (changing window size also lets the strings move with its corresponding cells). The second example doesn't. In the second example, the strings are layed over the table, they don't belong to a cell and fly over their borders when resizing the window... They are like ghosts!

    Can you explain this behaviour?

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

      Again: option.rect changes for each cell. It will be adapted to changes of column size, row size etc.

      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
      1
      • B Offline
        B Offline
        Binary91
        wrote on last edited by
        #13

        Oh yes, this makes sense... I forgot the fact that paint() is also called while resizing... ok everything is clear now. Thanks

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Binary91
          wrote on last edited by Binary91
          #14

          Maybe one last Question:
          Does it make any difference to the appeareance when using a custom item delegate in combination with QTableWidgetItem instead of using the custom delegate with plain cells? Does the custom delegate also effect to QTableWidgetItems or will they use their own display methods?

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

            No, these are just items holding data, the delegate will act just the same

            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
            • B Offline
              B Offline
              Binary91
              wrote on last edited by Binary91
              #16

              Ah, I see. So a delegate is really just a layer that is not interested in data that is already stored into a table. So I think it will not be possible for me to place data via delegate that should be clickable like a link, right? The click would go "through" the delegate and would only hit the underlying QTableWidgetItem...

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

                eventFilter comes to mind to handle that

                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
                • B Offline
                  B Offline
                  Binary91
                  wrote on last edited by
                  #18

                  alright, thank you for your live support! I think I can handle the rest by myself.

                  Cheers,

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    Binary91
                    wrote on last edited by
                    #19

                    Well, maybe I have one more question:
                    In my code, I subclass QItemDelegate but I only reimplement the paint function. So the editor behaviour should be the same as in default delegate mode.

                    What I'm asking myself now is, how the delegate (which, in my eyes, can be seen as a layer of data over the table) interacts with QTableWidgetItems. For a example, I inserted QTableWidgets in every table cell with a text "itemText". Also, I used the custom QItemDelegate and let the paint function paint a text "delegateText" over every cell.
                    The result is (as expected), that the "delegateText" is displayed over the "itemText". So the delegate is like a layer that is not interested in what the cell does.

                    BUT, what happens if I try to edit the QTableWidgetItem by double click? As expected, an editable cursor appears. But is this now the editor of the QTableWidgetItem or is it the editor of the QItemDelegate ?? And what would happen if I disable one of them?

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

                      The QTableWidgetItem is essentially a data container, it doesn't know about any editor.

                      It's the delegate that uses a factory that will return the corresponding editor based on the item content type.

                      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