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. ListView Custom delegate crash in paint

ListView Custom delegate crash in paint

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

    Hi,

    I have created my Listview with custom Delegate. The paint method looks like this:

    @void List_view_delegate::paint(QPainter * painter, const QStyleOptionViewItem & option,
    const QModelIndex & index) const
    {
    m_item_widget->resize(option.rect.size());

    // Update data of widget here.
    const QString name = index.data(Character_model::CharacterNameRole).toString();
    m_item_widget->set_name(name);

    QPalette pal;
    pal.setBrush(QPalette::Window, QBrush(QColor(Qt::transparent)));

    m_item_widget->setPalette(pal);

    // Paint the widget now.
    painter->save();
    painter->translate(option.rect.topLeft());
    m_item_widget->render(painter);
    painter->restore();
    }@

    This List_view is a part of a Widget which has a QPropertyAnimation set on its maximumWidth to give animated sliding of the widget. When the widget maximumWidth becomes 0, the paint() method of listview crashes in the render method.

    SOmebody has a clue??

    1 Reply Last reply
    0
    • S Offline
      S Offline
      smita30apr
      wrote on last edited by
      #2

      The output shows:

      QPaintDevice: Cannot destroy paint device that is being painted
      ASSERT: "enginePriv" in file kernel/qwidget.cpp, line 4725

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

        Hi,

        Silly question but why are you painting a widget which has no size ?

        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
          smita30apr
          wrote on last edited by
          #4

          No I am not painting on no size.

          The animation reduces the size but still paint event is called because animation is resizing the widget.

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

            What if you stop at one and then make the widget invisible rather that go to zero ?

            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
              smita30apr
              wrote on last edited by
              #6

              Actually I suspected that the widget is getting of size 0. I tried to print the option.rect.size() in paint() of my delegate and it prints:

              QSize(790, 182)
              QSize(790, 182)
              QSize(790, 182)
              QSize(596, 182)

              and after this it gives segmentation fault.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                smita30apr
                wrote on last edited by
                #7

                Strange part is that it asserts in Qt

                engine->d_func()

                That is where is asserting. I dont understand

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

                  Can you show a complete stack trace ?

                  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
                    smita30apr
                    wrote on last edited by
                    #9

                    I hope this helps:

                    http://pastebin.com/5tVsVEtE

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

                      What is Characters_view_delegate ?

                      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
                        smita30apr
                        wrote on last edited by
                        #11

                        Characters_view_delegate is my custom delegate for my QListView. I paint my delegate in paint. In the above code ,
                        List_view_delegate = Characters_view_delegate

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

                          Can you create a minimal example that shows the crash ?

                          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