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. Add widget right aligned to a QTableWidget cell
Forum Updated to NodeBB v4.3 + New Features

Add widget right aligned to a QTableWidget cell

Scheduled Pinned Locked Moved Solved General and Desktop
46 Posts 4 Posters 7.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.
  • H hbatalha

    @VRonin said in Add widget right aligned to a QTableWidget cell:

    Also me->pos() works in Qt5 but you need me->position() for Qt6

    here QRect::contains takes a QPoint but me->position is a QPointF, I will have to do some casting.

    Edit: I will just use QPointF::toPoint

    VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #36

    @hbatalha said in Add widget right aligned to a QTableWidget cell:

    here QRect::contains takes a QPoint but me->position is a QPointF, I will have to do some casting.

    Just call .toPoint() see TableWidgetDelegate::viewportEvent

    I have a question: in createEditor, I just deleted the two connect lines and signals are still being emitted. So what is the purpose of creating the MyButton object there?

    Those 2 lines deal with when the user is actually editing. In my original example the delegate was the default editor (usually a lineedit) + a button on the side. The default editor is used to change the contents of the cell. If the user starts editing the cell (doubleclick by default) the editor will pop up and you'll see that clicking on the buttons will not do anything unless you have those 2 connects.
    In a nutshell we have to handle 2 cases: when the delegate is just painting and when the editor is presented to the user

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    H 1 Reply Last reply
    0
    • VRoninV VRonin

      @hbatalha said in Add widget right aligned to a QTableWidget cell:

      here QRect::contains takes a QPoint but me->position is a QPointF, I will have to do some casting.

      Just call .toPoint() see TableWidgetDelegate::viewportEvent

      I have a question: in createEditor, I just deleted the two connect lines and signals are still being emitted. So what is the purpose of creating the MyButton object there?

      Those 2 lines deal with when the user is actually editing. In my original example the delegate was the default editor (usually a lineedit) + a button on the side. The default editor is used to change the contents of the cell. If the user starts editing the cell (doubleclick by default) the editor will pop up and you'll see that clicking on the buttons will not do anything unless you have those 2 connects.
      In a nutshell we have to handle 2 cases: when the delegate is just painting and when the editor is presented to the user

      H Offline
      H Offline
      hbatalha
      wrote on last edited by
      #37

      @VRonin said in Add widget right aligned to a QTableWidget cell:

      Those 2 lines deal with when the user is actually editing. In my original example the delegate was the default editor (usually a lineedit) + a button on the side. The default editor is used to change the contents of the cell. If the user starts editing the cell (doubleclick by default) the editor will pop up and you'll see that clicking on the buttons will not do anything unless you have those 2 connects.
      In a nutshell we have to handle 2 cases: when the delegate is just painting and when the editor is presented to the user

      Got it, thanks.

      Could you please answer me here?

      1 Reply Last reply
      0
      • JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #38

        @VRonin
        I hope I can hijack this thread now that the OP has had his questions answered?

        I know the crusade you are on. And I have to respect that the OP may have a lot of items, I don't know. But would you admit that --- without starting a flame-war --- this is one hell of a lot of code to add for a delegate approach if setCellWidget() would have done the job?

        VRoninV H 2 Replies Last reply
        0
        • JonBJ JonB

          @VRonin
          I hope I can hijack this thread now that the OP has had his questions answered?

          I know the crusade you are on. And I have to respect that the OP may have a lot of items, I don't know. But would you admit that --- without starting a flame-war --- this is one hell of a lot of code to add for a delegate approach if setCellWidget() would have done the job?

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #39

          @JonB said in Add widget right aligned to a QTableWidget cell:

          would you admit that this is one hell of a lot of code to add for a delegate approach

          I'll even go one step further, and say that for anything more complicated than adding a button, going down reimplementing paint is completely unreasonable. It still doesn't excuse setCellWidget(). You can always use something like this delegate (beware: old code) to have 1 widget taking care of painting every cell instead of having as many widgets as there are cells

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • JonBJ JonB

            @VRonin
            I hope I can hijack this thread now that the OP has had his questions answered?

            I know the crusade you are on. And I have to respect that the OP may have a lot of items, I don't know. But would you admit that --- without starting a flame-war --- this is one hell of a lot of code to add for a delegate approach if setCellWidget() would have done the job?

            H Offline
            H Offline
            hbatalha
            wrote on last edited by
            #40

            @JonB said in Add widget right aligned to a QTableWidget cell:

            Beware that this topic is not about replacing setCellWidget(), the one about setCellWidget() is still open.

            this is one hell of a lot of code to add for a delegate approach if setCellWidget() would have done the job?

            setCellWidget() is just awful when you have a chance of using a delegate instead. Since I discovered that I can use a delegate instead, having a setCellWidget has become very unsettling for me.

            JonBJ 1 Reply Last reply
            0
            • H hbatalha

              @JonB said in Add widget right aligned to a QTableWidget cell:

              Beware that this topic is not about replacing setCellWidget(), the one about setCellWidget() is still open.

              this is one hell of a lot of code to add for a delegate approach if setCellWidget() would have done the job?

              setCellWidget() is just awful when you have a chance of using a delegate instead. Since I discovered that I can use a delegate instead, having a setCellWidget has become very unsettling for me.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #41

              @hbatalha
              Thanks, I did wonder whether it was a different topic, but didn't try to go find it.

              Your sentiments must warm the cockles of @VRonin's heart ;-) But for those of us who value writing as little code as possble when there is built-in stuff it's not such good news. I do respect why delegates are a better choice, shame there is so much code to write.

              @VRonin should "publish" a library/class, QStyledItemWidgetDelegate, perhaps based on the code of his referred to in his last post, which does everything one might want from setCellWidget but in a delegate-y way, for everyone to use :) [Also, he should try to keep it down to, say, 10 lines...]

              VRoninV H 2 Replies Last reply
              0
              • JonBJ JonB

                @hbatalha
                Thanks, I did wonder whether it was a different topic, but didn't try to go find it.

                Your sentiments must warm the cockles of @VRonin's heart ;-) But for those of us who value writing as little code as possble when there is built-in stuff it's not such good news. I do respect why delegates are a better choice, shame there is so much code to write.

                @VRonin should "publish" a library/class, QStyledItemWidgetDelegate, perhaps based on the code of his referred to in his last post, which does everything one might want from setCellWidget but in a delegate-y way, for everyone to use :) [Also, he should try to keep it down to, say, 10 lines...]

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #42

                @JonB said in Add widget right aligned to a QTableWidget cell:

                Also, he should try to keep it down to, say, 10 lines...

                ahahah!

                should "publish" a library/class, QStyledItemWidgetDelegate

                Already on my TODO list

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                H 1 Reply Last reply
                1
                • JonBJ JonB

                  @hbatalha
                  Thanks, I did wonder whether it was a different topic, but didn't try to go find it.

                  Your sentiments must warm the cockles of @VRonin's heart ;-) But for those of us who value writing as little code as possble when there is built-in stuff it's not such good news. I do respect why delegates are a better choice, shame there is so much code to write.

                  @VRonin should "publish" a library/class, QStyledItemWidgetDelegate, perhaps based on the code of his referred to in his last post, which does everything one might want from setCellWidget but in a delegate-y way, for everyone to use :) [Also, he should try to keep it down to, say, 10 lines...]

                  H Offline
                  H Offline
                  hbatalha
                  wrote on last edited by hbatalha
                  #43

                  @JonB said in Add widget right aligned to a QTableWidget cell:

                  @VRonin should "publish" a library/class, QStyledItemWidgetDelegate, perhaps based on the code of his referred to in his last post, which does everything one might want from setCellWidget but in a delegate-y way, for everyone to use :) [Also, he should try to keep it down to, say, 10 lines...]

                  I was about to say that. Maybe propose the library to the Qt team to add to the official release(if that's how it is done)

                  1 Reply Last reply
                  0
                  • VRoninV VRonin

                    @JonB said in Add widget right aligned to a QTableWidget cell:

                    Also, he should try to keep it down to, say, 10 lines...

                    ahahah!

                    should "publish" a library/class, QStyledItemWidgetDelegate

                    Already on my TODO list

                    H Offline
                    H Offline
                    hbatalha
                    wrote on last edited by hbatalha
                    #44

                    @VRonin I have a simple question: is it possible to use setItemDelegateForRow and setItemDelegateForRow at the same view(same row)?

                    VRoninV 1 Reply Last reply
                    0
                    • H hbatalha

                      @VRonin I have a simple question: is it possible to use setItemDelegateForRow and setItemDelegateForRow at the same view(same row)?

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #45

                      @hbatalha said in Add widget right aligned to a QTableWidget cell:

                      @VRonin I have a simple question: is it possible to use setItemDelegateForRow and setItemDelegateForRow at the same view(same row)?

                      I assume you mean setItemDelegateForRow and setItemDelegateForColumn.
                      from https://doc.qt.io/qt-5/qabstractitemview.html#setItemDelegateForRow

                      Note: If a delegate has been assigned to both a row and a column, the row delegate will take precedence and manage the intersecting cell index.

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      H 1 Reply Last reply
                      2
                      • VRoninV VRonin

                        @hbatalha said in Add widget right aligned to a QTableWidget cell:

                        @VRonin I have a simple question: is it possible to use setItemDelegateForRow and setItemDelegateForRow at the same view(same row)?

                        I assume you mean setItemDelegateForRow and setItemDelegateForColumn.
                        from https://doc.qt.io/qt-5/qabstractitemview.html#setItemDelegateForRow

                        Note: If a delegate has been assigned to both a row and a column, the row delegate will take precedence and manage the intersecting cell index.

                        H Offline
                        H Offline
                        hbatalha
                        wrote on last edited by
                        #46

                        @VRonin said in Add widget right aligned to a QTableWidget cell:

                        I assume you mean setItemDelegateForRow and setItemDelegateForColumn.

                        yes, I copied and pasted n forgot to modify before submitting.

                        Thanks

                        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