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 update height of QStandardItem/Delegate?
QtWS25 Last Chance

How to update height of QStandardItem/Delegate?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++ qtdelegatesizehint
16 Posts 3 Posters 1.2k 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
    StudentScripter
    wrote on last edited by StudentScripter
    #1

    So i have a delegate inside a qlistview and as an editor i define my own widget "section" that is a scrollarea itself and can expand. But how can i update the size of the Delegate when the widgets size changes? Can anyone hint me the way? Thanks in advance. :)

    7a3dcc64-c308-4a7f-be7b-68a781090ccb-image.png
    817db633-d2c1-4358-a21e-8e6217f720fb-image.png
    Bugging out really wierd after closing cause no new SizeHint to delegate.
    ad079308-05f0-4670-9101-4b71f9559fe7-image.png

    #include "modulitemdelegate.h"
    #include <QLineEdit>
    #include <QFormLayout>
    #include <QComboBox>
    #include "Section.h"
    
    
    modulitemDelegate::modulitemDelegate(QObject *parent)
        : QStyledItemDelegate{parent}
    {}
    
    
    
    QWidget *modulitemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    
    
        Section* section = new Section("Section " + QString::number(1), 30, true, true, false, parent);
        section->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    
    
        connect(section, &Section::SendSizeUpdate, this, &modulitemDelegate::ReceiveSizeUpdate);
    
        // Erstelle Layout und fülle es mit Widgets für die Section
        auto* formLayout1 = new QFormLayout();
        QLineEdit *lineEdit1 = new QLineEdit();
        QLineEdit *lineEdit2 = new QLineEdit();
        QComboBox *comboBox = new QComboBox();
        formLayout1->addRow("Label 1:", lineEdit1);
        formLayout1->addRow("Label 2:", lineEdit2);
        formLayout1->addRow("Combo Box:", comboBox);
    
        // Setze das Layout für die Section
        section->setContentLayout(*formLayout1);
    
    
    
    
    
    
        return section;
    }
    
    void modulitemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    {
    
    }
    
    void modulitemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    {
    
    }
    
    
    
    QSize modulitemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    
    
        // Gib den Standard-SizeHint zurück
        QSize s = QStyledItemDelegate::sizeHint(option, index);
    
    
    
        return s;
    }
    
    

    Anyone can help? @JonB

    JonBJ 1 Reply Last reply
    0
    • S StudentScripter

      So i have a delegate inside a qlistview and as an editor i define my own widget "section" that is a scrollarea itself and can expand. But how can i update the size of the Delegate when the widgets size changes? Can anyone hint me the way? Thanks in advance. :)

      7a3dcc64-c308-4a7f-be7b-68a781090ccb-image.png
      817db633-d2c1-4358-a21e-8e6217f720fb-image.png
      Bugging out really wierd after closing cause no new SizeHint to delegate.
      ad079308-05f0-4670-9101-4b71f9559fe7-image.png

      #include "modulitemdelegate.h"
      #include <QLineEdit>
      #include <QFormLayout>
      #include <QComboBox>
      #include "Section.h"
      
      
      modulitemDelegate::modulitemDelegate(QObject *parent)
          : QStyledItemDelegate{parent}
      {}
      
      
      
      QWidget *modulitemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
      
      
          Section* section = new Section("Section " + QString::number(1), 30, true, true, false, parent);
          section->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
      
      
          connect(section, &Section::SendSizeUpdate, this, &modulitemDelegate::ReceiveSizeUpdate);
      
          // Erstelle Layout und fülle es mit Widgets für die Section
          auto* formLayout1 = new QFormLayout();
          QLineEdit *lineEdit1 = new QLineEdit();
          QLineEdit *lineEdit2 = new QLineEdit();
          QComboBox *comboBox = new QComboBox();
          formLayout1->addRow("Label 1:", lineEdit1);
          formLayout1->addRow("Label 2:", lineEdit2);
          formLayout1->addRow("Combo Box:", comboBox);
      
          // Setze das Layout für die Section
          section->setContentLayout(*formLayout1);
      
      
      
      
      
      
          return section;
      }
      
      void modulitemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
      {
      
      }
      
      void modulitemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
      {
      
      }
      
      
      
      QSize modulitemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
      
      
          // Gib den Standard-SizeHint zurück
          QSize s = QStyledItemDelegate::sizeHint(option, index);
      
      
      
          return s;
      }
      
      

      Anyone can help? @JonB

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

      @StudentScripter I only know of making sizeHint() work for the correct state.

      SGaistS S 2 Replies Last reply
      0
      • JonBJ JonB

        @StudentScripter I only know of making sizeHint() work for the correct state.

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Seeing the size of the delegate, are you certain that you want to keep the editor locked in the cell ? It seems that it would be better shown outside of it.

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

        S 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Seeing the size of the delegate, are you certain that you want to keep the editor locked in the cell ? It seems that it would be better shown outside of it.

          S Offline
          S Offline
          StudentScripter
          wrote on last edited by
          #4

          @SGaist Hey thanks for responding. :) What exatly do you mean with showing it outside? Isn't an delegate thought to show within one cell. Could may elaborate on what you mean and how to do it. That would be very helpful.

          My goal is a list like on the right side of Godot, but with rearangable dropdown menus. The menus shown switch depending on which element is clicked.
          2e6ce866-9307-4ce6-aa60-38a833298817-image.png

          1 Reply Last reply
          0
          • JonBJ JonB

            @StudentScripter I only know of making sizeHint() work for the correct state.

            S Offline
            S Offline
            StudentScripter
            wrote on last edited by
            #5

            @JonB I tryed that in a later version of my code but had no success. But i'll go for the error hunt. I update with new code when i really can't figure it out myself. :) Thanks Jon.

            SGaistS 1 Reply Last reply
            0
            • S StudentScripter

              @JonB I tryed that in a later version of my code but had no success. But i'll go for the error hunt. I update with new code when i really can't figure it out myself. :) Thanks Jon.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              When the editor is big and complex, it might be better to have it off cell.

              That said, I think you might be taking the wrong approach here. The inspector on the right seems to be a full fledged widget not a delegate.

              I see a combo-box at the top which is likely a selector that will trigger the selection of the current item to show. Once selected, the inspector will be loaded with the detail for this item. This could be accomplished with a QDataWidgetMapper.

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

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                When the editor is big and complex, it might be better to have it off cell.

                That said, I think you might be taking the wrong approach here. The inspector on the right seems to be a full fledged widget not a delegate.

                I see a combo-box at the top which is likely a selector that will trigger the selection of the current item to show. Once selected, the inspector will be loaded with the detail for this item. This could be accomplished with a QDataWidgetMapper.

                S Offline
                S Offline
                StudentScripter
                wrote on last edited by
                #7

                @SGaist So no listview or widget? But i want to have many of such modules which should be reorderable by drag and drop, so i thought i could harness the build in dnd functionality of qlistview or qlistwidget.

                SGaistS 1 Reply Last reply
                0
                • S StudentScripter

                  @SGaist So no listview or widget? But i want to have many of such modules which should be reorderable by drag and drop, so i thought i could harness the build in dnd functionality of qlistview or qlistwidget.

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @StudentScripter can you explain what you mean by module ?

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

                  S 2 Replies Last reply
                  0
                  • SGaistS SGaist

                    @StudentScripter can you explain what you mean by module ?

                    S Offline
                    S Offline
                    StudentScripter
                    wrote on last edited by
                    #9

                    @SGaist One Dropdown section with all the widgets that are into such a dropdown.

                    So for example modul1/dropdown1:
                    -4 lineedits for width, height, posx, posy

                    modul2/dropdown2:
                    -checkbox for hiding elements in the scene
                    -lineedit for setting the name of the item ins scene

                    and so on you get the point. :) Have a nice weekend.

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      @StudentScripter can you explain what you mean by module ?

                      S Offline
                      S Offline
                      StudentScripter
                      wrote on last edited by
                      #10

                      @SGaist Or should i use indiviual widgets and implement drag and drop within a layout? How to make this efficient? Setting all widgets not used parent to nullptr? Or what should it do?

                      SGaistS 1 Reply Last reply
                      0
                      • S StudentScripter

                        @SGaist Or should i use indiviual widgets and implement drag and drop within a layout? How to make this efficient? Setting all widgets not used parent to nullptr? Or what should it do?

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @StudentScripter Did you consider having a "edit mode" where you move things around ?

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

                        S 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          @StudentScripter Did you consider having a "edit mode" where you move things around ?

                          S Offline
                          S Offline
                          StudentScripter
                          wrote on last edited by
                          #12

                          @SGaist Preferabily i would like to not have an edit mode, if possible. But whats your idea with an edit mode?

                          Also if not using that. Would implementing drag and drop inside they layout be the way or is there any other better methode? Thank you very much.

                          SGaistS 1 Reply Last reply
                          0
                          • S StudentScripter

                            @SGaist Preferabily i would like to not have an edit mode, if possible. But whats your idea with an edit mode?

                            Also if not using that. Would implementing drag and drop inside they layout be the way or is there any other better methode? Thank you very much.

                            SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @StudentScripter with the edit mode, you can make your widgets look a bit like a dashboard where you move things around a bit like on iOS when you long press on the screen and things start wobbling. You can then move them around and once it's done you can again use them.

                            As for your second question, it's rather at the containing widget level that you would do that. You would move things around in the layout but it's not the layout that is responsible for the D&D part as layouts do not have a "body".

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

                            S 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              @StudentScripter with the edit mode, you can make your widgets look a bit like a dashboard where you move things around a bit like on iOS when you long press on the screen and things start wobbling. You can then move them around and once it's done you can again use them.

                              As for your second question, it's rather at the containing widget level that you would do that. You would move things around in the layout but it's not the layout that is responsible for the D&D part as layouts do not have a "body".

                              S Offline
                              S Offline
                              StudentScripter
                              wrote on last edited by
                              #14

                              @SGaist Yeah i primarily meant drag and drop within the qscrollarea where the layout is located. But is this really my best option? What to keep in mind when having many widgets? Or is removing the widgets that are currently not supposed to be shown from the layout enough? Have good 1st may.

                              SGaistS 1 Reply Last reply
                              0
                              • S StudentScripter

                                @SGaist Yeah i primarily meant drag and drop within the qscrollarea where the layout is located. But is this really my best option? What to keep in mind when having many widgets? Or is removing the widgets that are currently not supposed to be shown from the layout enough? Have good 1st may.

                                SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @StudentScripter Things to keep in mind is that if you have a QScrollArea that contains the equivalent of multiple screens worth of widgets, then it won't be nice for your users.

                                You should start by drawing your widgets and then think about how many are necessary, how they should be shown, etc. And if possible discuss that with people from your target audience.

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

                                S 1 Reply Last reply
                                1
                                • SGaistS SGaist

                                  @StudentScripter Things to keep in mind is that if you have a QScrollArea that contains the equivalent of multiple screens worth of widgets, then it won't be nice for your users.

                                  You should start by drawing your widgets and then think about how many are necessary, how they should be shown, etc. And if possible discuss that with people from your target audience.

                                  S Offline
                                  S Offline
                                  StudentScripter
                                  wrote on last edited by
                                  #16

                                  @SGaist Thank you very much. One last questions before closing this thread:

                                  1. Does using setListWigetItem (QListWidget) make an difference in performance compared to just using the widgets inside a scrollarea or is the overhead the same?

                                  Have a nice day! :)

                                  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