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

Issue with successive calls to QStackedWidget::setCurrentWidget(QWidget*)



  • Hi All!

    Platform specs: Linux kubuntu 14
    QT version: 4.7.1

    On my current project I have a main GUI that contains a few QPushButtons that are associated with a QStackedWidget object.
    For simplicity think about a main GUI window with two buttons and a main area to display page1 and page2.

    A press on first button will call stackedWidget->setCurrentWidget(page1)
    A press on second button will call stackedWidget->setCurrentWidget(page2)

    page1 and page2 display remote external applications that are forwarded via ssh and embedded in a QX11EmbedContainer.

    When browsing between page1 and page2 i need to perform a lot of pre processing -
    More specifically, if I am on page1 and press on button to move to page2 I perform the following:

    1. Disconnect connection with remote application displayed on page 1.
    2. Re-connect with remote application to display it back on page2.
      And vice versa when moving from page2 to page1.

    This all functions as intended except for the fact I have some flickering caused by all the preprocessing when moving between the stacked widgets.

    A solution I want to achieve is to "hide" this flickering from the user by performing the following:

    void onShowPage1Pushed()
    {
    stackedWidget->setCurrentWidget(temp_page)
    showFirstApp()
    hideSecondApp()
    stackedWidget->setCurrentWidget(page_of_first_app)
    }
    

    But the temp_page is never displayed as if the preprocessing performed between the setCurrentWidget() calls is too short, and I end up experiencing all the flickering involved with disconnection and connection of remote applications and embedding them in containers.

    Is there a way to perform this maneuver? To set a blank page from the stack as the current widget until the preprocessing is done and only then set the wanted page?

    The reason why I need to hide the second application when moving to display first application isn't important but it's mandatory.

    Your help is much appreciated!



  • @walle19
    I'm not going to comment on the whys & wherefores of what you are choosing to do. Sounds nasty to me, 'nuff said.

    But in terms of why your your code does not behave as you seem to wish. Shows/hides/setting current stacked widget and so on won't have any visual effect unless you do something like QCoreApplication::processEvents(). Assuming you have some time-consuming processing to do after setCurrentWidget(temp_page), try shoving a process events on the following line and see how you app behaves.



  • @walle19
    I'm not going to comment on the whys & wherefores of what you are choosing to do. Sounds nasty to me, 'nuff said.

    But in terms of why your your code does not behave as you seem to wish. Shows/hides/setting current stacked widget and so on won't have any visual effect unless you do something like QCoreApplication::processEvents(). Assuming you have some time-consuming processing to do after setCurrentWidget(temp_page), try shoving a process events on the following line and see how you app behaves.



  • @JonB said in Issue with successive calls to QStackedWidget::setCurrentWidget(QWidget*):

    try shoving a process events on the following line and see how you app behaves.

    Hi Jon,
    This seems to help. I'll read about QCoreApplication::processEvents() to understand the consequence of this call.

    About the wherefores, i'll be glad to get your input. Even if I can't implement it, its always good to get new ideas or insights from more experienced programmers. I'll be glad to explore new paths.


Log in to reply