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. Custom editor for a delegate
Forum Updated to NodeBB v4.3 + New Features

Custom editor for a delegate

Scheduled Pinned Locked Moved Unsolved General and Desktop
29 Posts 3 Posters 9.0k 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.
  • M Offline
    M Offline
    Maser
    wrote on 20 Jun 2016, 16:40 last edited by Maser
    #3

    No))) Well i was, but i forgot to call standard constructor from QWidget in my cpp. Now it pressing my editor in the cell of the tableview. Can i draw on top of the view?

    J 1 Reply Last reply 20 Jun 2016, 16:45
    0
    • M Maser
      20 Jun 2016, 16:40

      No))) Well i was, but i forgot to call standard constructor from QWidget in my cpp. Now it pressing my editor in the cell of the tableview. Can i draw on top of the view?

      J Offline
      J Offline
      Joel Bodenmann
      wrote on 20 Jun 2016, 16:45 last edited by Joel Bodenmann
      #4

      To add to what @mrjj mentioned with the parent: You are actually supposed to assign the parent passed to the createEditor() function:

      QWidget* ComboboxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
      {
          Q_UNUSED(option)
          Q_UNUSED(index)
      
          QComboBox* combobox = new QComboBox(parent);
          combobox->addItems({"Foo", "Bar", "mrjj"});
      
          return combobox;
      }
      

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Maser
        wrote on 20 Jun 2016, 16:46 last edited by
        #5

        @Joel. yes, i did.

        M 1 Reply Last reply 20 Jun 2016, 16:53
        0
        • M Maser
          20 Jun 2016, 16:46

          @Joel. yes, i did.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 20 Jun 2016, 16:53 last edited by
          #6

          @Maser said:

          Can i draw on top of the view?

          yes , you can override paintEvent and call base paint then then draw your self but
          often there are better ways :)

          Can I ask why you want to draw on view?

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Maser
            wrote on 20 Jun 2016, 17:07 last edited by
            #7

            Well, my editor contains a number of images, from where i can choose one or several. as a markup that images are chosen i draw a red circle, around the activated ones. And the pictures are bigger, so they dont fit in the cell and the cell have to be resized when i draw it in the cell. So i figured i just draw it on top with a predefined size of a editorwidget.

            M 1 Reply Last reply 20 Jun 2016, 17:10
            0
            • M Maser
              20 Jun 2016, 17:07

              Well, my editor contains a number of images, from where i can choose one or several. as a markup that images are chosen i draw a red circle, around the activated ones. And the pictures are bigger, so they dont fit in the cell and the cell have to be resized when i draw it in the cell. So i figured i just draw it on top with a predefined size of a editorwidget.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 20 Jun 2016, 17:10 last edited by
              #8

              @Maser
              ok. So its when you select the images, you want to draw over the view ? or
              after you selected an image?

              Im not sure how will it will work with scrolling etc.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Maser
                wrote on 20 Jun 2016, 17:21 last edited by
                #9

                No, no. I want my editor widget drawn on top when i start editing the cell. After i made the editing, the editor is gone and the changed state or whatever in inside the cell. Just for editing.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Maser
                  wrote on 20 Jun 2016, 20:32 last edited by Maser
                  #10

                  So any suggestions how i do this painting over? I suppose i have to somehow get the coordinates of the cell, then draw a barebone widget und maybe adjust it in the tableview frame. But i dont know where to start. Are there some examples on that?

                  M 1 Reply Last reply 21 Jun 2016, 06:04
                  0
                  • M Maser
                    20 Jun 2016, 20:32

                    So any suggestions how i do this painting over? I suppose i have to somehow get the coordinates of the cell, then draw a barebone widget und maybe adjust it in the tableview frame. But i dont know where to start. Are there some examples on that?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 21 Jun 2016, 06:04 last edited by
                    #11

                    @Maser
                    Hi,
                    Maybe you should look into a delegate ?
                    http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html

                    A delegate is the normal way to change how content is drawn in each cell.

                    Painting on the actual view will often have side effects with scrolling etc.

                    If you want to see, you will override the paintEvent virtual function
                    and paint there.

                    1 Reply Last reply
                    2
                    • M Offline
                      M Offline
                      Maser
                      wrote on 21 Jun 2016, 11:17 last edited by
                      #12

                      Im using a delegate. but i want the editor of the delegate drawn over the cell. I just need a hin how i connect the coordinates and draw a barebone widget. In wont have to be scrollable (yet).

                      M 1 Reply Last reply 21 Jun 2016, 12:07
                      0
                      • M Maser
                        21 Jun 2016, 11:17

                        Im using a delegate. but i want the editor of the delegate drawn over the cell. I just need a hin how i connect the coordinates and draw a barebone widget. In wont have to be scrollable (yet).

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 21 Jun 2016, 12:07 last edited by
                        #13

                        @Maser

                        Ok. Im not really following what u need. sorry.

                        In any case, you can override paintEvent for any widget and draw.
                        Notice that you cannot draw outside of the widgets client area so
                        make sure u override the paint for the actual widget u want to draw on.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Maser
                          wrote on 21 Jun 2016, 17:49 last edited by Maser
                          #14

                          It seems overriding paintevent doesnt work. What does work(at least partially) is reimplementing updateEditorGeometry from the delegate. When i give the specific cell a bigger size for the editor it paints it bigger. Even the choosing works, but not when there is another cell under from the tableview under my editor-buttons. Dont yet know how to solve that.

                          M 1 Reply Last reply 21 Jun 2016, 17:52
                          0
                          • M Maser
                            21 Jun 2016, 17:49

                            It seems overriding paintevent doesnt work. What does work(at least partially) is reimplementing updateEditorGeometry from the delegate. When i give the specific cell a bigger size for the editor it paints it bigger. Even the choosing works, but not when there is another cell under from the tableview under my editor-buttons. Dont yet know how to solve that.

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 21 Jun 2016, 17:52 last edited by
                            #15

                            @Maser
                            ok, can we see pic ?

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              Maser
                              wrote on 21 Jun 2016, 18:04 last edited by
                              #16

                              http://www.picfront.org/d/9q7X
                              I marked the cell from which the editor has been activated. Problem is, as long is the items are of this cell or outside of the table, i can click them. if the are above other cells, the editor closes.

                              M 1 Reply Last reply 21 Jun 2016, 18:08
                              0
                              • M Maser
                                21 Jun 2016, 18:04

                                http://www.picfront.org/d/9q7X
                                I marked the cell from which the editor has been activated. Problem is, as long is the items are of this cell or outside of the table, i can click them. if the are above other cells, the editor closes.

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 21 Jun 2016, 18:08 last edited by
                                #17

                                @Maser
                                Could you not just pop a dialog with
                                all the images and let user select one?

                                Or use a combobox with a delegate ?
                                http://www.qtcentre.org/threads/26376-Using-images-in-QComboBox

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Maser
                                  wrote on 21 Jun 2016, 18:17 last edited by Maser
                                  #18

                                  This is a good idea)
                                  But since im trying to learn Qt, i will save it for the emergency plan)
                                  When i have a customer who wants it the exact way he described it, i wanna know how to do it, no matter of the cost)
                                  Have you an idea why the over cells interfere with my editor and how i can solve it?

                                  M 1 Reply Last reply 21 Jun 2016, 18:25
                                  0
                                  • M Maser
                                    21 Jun 2016, 18:17

                                    This is a good idea)
                                    But since im trying to learn Qt, i will save it for the emergency plan)
                                    When i have a customer who wants it the exact way he described it, i wanna know how to do it, no matter of the cost)
                                    Have you an idea why the over cells interfere with my editor and how i can solve it?

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 21 Jun 2016, 18:25 last edited by
                                    #19

                                    @Maser said:

                                    Have you an idea why the over cells interfere with my editor and how i can solve it?

                                    I assume that click goes to real cell as the images is just painted over it
                                    so u can not click on them as such.

                                    1 Reply Last reply
                                    1
                                    • M Offline
                                      M Offline
                                      Maser
                                      wrote on 21 Jun 2016, 18:28 last edited by Maser
                                      #20

                                      No, i can. I told you. if i aim right in the black marked cell, i can click and unclick the three left items, i can also click the three right items. Just when i click anywhere in the tablecells, the editor is gone.

                                      PS: Maybe i have to somehow resize the "working area" of the cell to to fit my editor. I mean the clickable area associated with the cell. Idea on that?

                                      M 1 Reply Last reply 21 Jun 2016, 19:33
                                      0
                                      • M Maser
                                        21 Jun 2016, 18:28

                                        No, i can. I told you. if i aim right in the black marked cell, i can click and unclick the three left items, i can also click the three right items. Just when i click anywhere in the tablecells, the editor is gone.

                                        PS: Maybe i have to somehow resize the "working area" of the cell to to fit my editor. I mean the clickable area associated with the cell. Idea on that?

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 21 Jun 2016, 19:33 last edited by
                                        #21

                                        @Maser
                                        Hi
                                        The cell has the size it has.

                                        The Editor can be anything so it should be possible
                                        to float a transparent widget where u paint the pics
                                        and get the selection.

                                        Can u show code for editor creation ?

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          Maser
                                          wrote on 21 Jun 2016, 19:44 last edited by Maser
                                          #22
                                          class ClickableIconHolder : public QWidget
                                          {
                                              Q_OBJECT
                                          public:
                                              ClickableIconHolder(uint Mark, QWidget *parent = 0);
                                              QSize sizeHint() const Q_DECL_OVERRIDE;
                                          signals:
                                              void editingFinished();
                                          protected:
                                              void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
                                          private:
                                              QHBoxLayout *hbLayout;
                                              ClickableIcon *ci1 = 0;
                                              ClickableIcon *ci2 = 0;
                                              ClickableIcon *ci3 = 0;
                                              ClickableIcon *ci4 = 0;
                                              ClickableIcon *ci5 = 0;
                                              ClickableIcon *ci6 = 0;
                                              ClickableIcon *ci7 = 0;
                                          };
                                          

                                          Here is the header of the editor-widget. I create some clickable QLabel and add them to a HBoxLayout, thats all in general. I dont do nothing in the paintevent yet.

                                          1 Reply Last reply
                                          0

                                          12/29

                                          21 Jun 2016, 11:17

                                          • Login

                                          • Login or register to search.
                                          12 out of 29
                                          • First post
                                            12/29
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved