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. Widget of QScrollArea event filter issue
Qt 6.11 is out! See what's new in the release blog

Widget of QScrollArea event filter issue

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 634 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
    spobit
    wrote on last edited by spobit
    #1

    See the code from qt source:

    void QScrollArea::setWidget(QWidget *widget)
    {
        Q_D(QScrollArea);
        if (widget == d->widget || !widget)
            return;
    
        delete d->widget;
        d->widget = 0;
        d->hbar->setValue(0);
        d->vbar->setValue(0);
        if (widget->parentWidget() != d->viewport)
            widget->setParent(d->viewport);
        if (!widget->testAttribute(Qt::WA_Resized))
            widget->resize(widget->sizeHint());
        d->widget = widget;
        d->widget->setAutoFillBackground(true);
        widget->installEventFilter(this);
        d->widgetSize = QSize();
        d->updateScrollBars();
        d->widget->show();
    
    }
    

    When someone uses QScrollArea as container, and maybe change the widget of QScrollArea to other; then, the code widget->installEventFilter(this);, who to break it? there maybe a big issue.

    I do it as follow:

    widget->removeEventFilter(widget->parent());
    widget->removeEventFilter(widget->parent() ? widget->parent()->parent() : nullptr);
    widget->setParent(nullptr);
    

    Maybe better way for you!

    1 Reply Last reply
    0
    • AndeolA Offline
      AndeolA Offline
      Andeol
      wrote on last edited by
      #3

      You are worried the eventfilter stays after the contained widget has been changed? But the line
      delete d->widget deletes the previously contained widget. And deleting the widget is enough to stop the filter. So I don't think there is an issue with the way QScrollArea::setWidget is coded.

      Developer for R++ : https://rplusplus.com/

      S 1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        And what's you question/ problem here?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • AndeolA Offline
          AndeolA Offline
          Andeol
          wrote on last edited by
          #3

          You are worried the eventfilter stays after the contained widget has been changed? But the line
          delete d->widget deletes the previously contained widget. And deleting the widget is enough to stop the filter. So I don't think there is an issue with the way QScrollArea::setWidget is coded.

          Developer for R++ : https://rplusplus.com/

          S 1 Reply Last reply
          1
          • AndeolA Andeol

            You are worried the eventfilter stays after the contained widget has been changed? But the line
            delete d->widget deletes the previously contained widget. And deleting the widget is enough to stop the filter. So I don't think there is an issue with the way QScrollArea::setWidget is coded.

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

            @Andeol
            Thank you! It`s a important code and I ignored it.

            The container is not my coding, but it can`t delete the component, and then recreate it. Maybe needs a interface to take widget, so, I See:

            QWidget *QScrollArea::takeWidget()
            {
                Q_D(QScrollArea);
                QWidget *w = d->widget;
                d->widget = 0;
                if (w)
                    w->setParent(0);
                return w;
            }
            
            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