Results 1 to 2 of 2

Thread: QScrollArea scrolls to top when hiding QPushButton

  1. #1
    Join Date
    Aug 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QScrollArea scrolls to top when hiding QPushButton

    I have a custom datetimewidget that is set up like this:

    1. When invalid datetime:
    datetime_invalid.PNG
    - 2 QPushButtons showing that the date and time are invalid.

    2. When valid datetime:
    datetime_valid.PNG
    - A QDateEdit and a QTimeEdit. These are hidden if invalid datetime, and shown only if valid datetime

    This datetimewidget is placed within a QGroupBox and then on a QScrollArea.

    If starting out with an invalid datetime, clicking one of the buttons give you a valid datetime, hides the buttons and shows the controls. This works fine, except that the QScrollArea scrolls to top. Does anyone have an idea on where to look for what initiates this?

    I've found some hints, but are still stuck on this:
    • If I drop the QPushButton.hide() on the button that is hit, I don't get the unwanted scroll-behaviour. However, I really want to hide this button...
    • If I drop the blockSignals true/false around the setting of current datetime to the QDateEdit and QTimeEdit, I don't get this problem. However, the blockSignals are needed to avoid signals of edited datetime when it's actually not edited.


    Thanks alot!
    TomasL

  2. #2
    Join Date
    Aug 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QScrollArea scrolls to top when hiding QPushButton

    Answering myself here:

    This issue was actually caused by the fact that hiding a button gives focus to the next widget in the layout. In this case, the datetimewidget was placed at the bottom, and the next widget in the layout was the widget at the very top of the scroll area.

    This was solved by
    setFocusPolicy(Qt::StrongFocus); //on the datetimewidget
    and
    setFocusPolicy(Qt::NoFocus); //on the QPushButtons showing invalid date and time

Similar Threads

  1. QScrollArea that only scrolls vertically
    By stephelton in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2013, 11:48
  2. QListView scrolls to top when rows inserted
    By woodtluk in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2010, 16:26
  3. Q Scroll Area that scrolls??
    By hakermania in forum Newbie
    Replies: 6
    Last Post: 24th August 2010, 19:48
  4. Hiding QPushButton String in QSigalMapper built keypad.
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 12th August 2010, 07:06
  5. QTreeWidget - scrolls to top when removing items
    By durbrak in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2006, 22:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.