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

Setting Focus on Button and let verticalScrollbar to Top does not work



  • Hi all,

    I have a StackedWidget containing a Scrollbar with some labels and Buttons in it.
    The labels are placed at the top and the buttons below.

    In the constructor I set the focus to the button (preselected) scrollbar moves a bit down (so far its okay)

    But I wanted to have the scrollbar at top at startup so I thought I just set the Scrollbar to 0

    @
    ui->pushButtonDefault->setFocus();
    ui->scrollArea->verticalScrollBar()->setValue( 0 ); //scroll to top
    @

    But the scrollbar does not move to the top if the button setFocus is called before, this only works if I do not set the Focus to the Button or let a Timer timeout slot call the scrollbar function after some seconds.

    Does anyone have an idea why this happens? Is it not allowed to set these in this combination?

    Many Thanks