Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting a translucent background to current widget of QStackedWidget



  • Hi All,

    Platform: Linux Kubuntu 14
    QT Version: 4.7.1

    I am interested in using a busy indicator spinner when long processing is performed
    moving between a QStackedWidget pages.

    For example, I defined QStackWidget with three pages. One of them is a page that displays a busy indicator spinner.
    When moving from page1 to page2 some processing is performed and for the period of time it takes I want to display the busy indicator with translucent background. I tried this but no success:

    spinner->setAttributes(Qt::TranslucentBackground, true) 
    

    My question is - Can I make the background of the spinner widget translucent so that when it is displayed (and spinning) it will show in the background the last page or widget I was at.
    To make clear - When moving from page1 to page2 , show spinner on top of page1 but keep the spinners background translucent so we still see page1. When processing finishes show page2.

    void on_moveFrom1to2_clicked() {
    stackedWidget->setCurrentWidget(spinner)
    processing()
    stackedWidget->setCurrentWidget(page2)
    }
    

    If this approach is wrong I would appreciate any suggestions

    Thanks for the help


  • Lifetime Qt Champion

    Hi
    Is the actual spinner GIF image transparent?

    It should be possible to overlay it but not sure what part is missing.
    Update: Bonnie made me realize what you really asking and only one page is visible
    at a time so you have to overlay the spinner to the current page.

    I used this overlay widget
    https://stackoverflow.com/questions/19199863/draw-rectangular-overlay-on-qwidget-at-click

    You might want to remove
    setAttribute(Qt::WA_TransparentForMouseEvents);
    so it will eat any mouse clicks.



  • @walle19
    Yes your approach is wrong.
    You shouldn't define the spinner as a page because in QStackedWidget when you switch to one page, others will be hidden.
    Even the background is translucent you still won't see other pages.
    Just create it as a child widget of QStackedWidget (or any parent widget) and control the geometry and visibility yourself.
    And another thing to mention, will your processing() function block the main thread? If it will then the spinner may be not shown properly.


Log in to reply