Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7527789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:11:41+00:00 2026-05-30T04:11:41+00:00

I have a QTreeWidget that reads data from an XML file. If at any

  • 0

I have a QTreeWidget that reads data from an XML file. If at any point the XML file is changed (think many users accessing said file at one time), the QTreeWidget is repopulated with clear and a re-read. If a user is anywhere but the top of the QTreeWidget, scroll-wise, and it gets repopulated after a clear, they’re taken back to the top by default.

Question is, can one get the ‘scroll value’ of a QTreeWidget and then go back to that same value after a repopulation? If so, how? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:11:42+00:00Added an answer on May 30, 2026 at 4:11 am

    You could scroll to the actual previous values, like you are asking, but are you sure your results will always be the same size? Those numbers could be meaningless in terms of taking you to the right spot again. But just for reference, you would have to access the scroll bar, take its value, then perform your repopulation, and then scroll that value again:

    bar = treeWidget.verticalScrollBar()
    yScroll = bar.value()
    # repopulate here ...
    treeWidget.scrollContentsBy(0, yScroll)
    

    But a more useful approach would be to find the item that is current in view or of interest, then repopulate your tree, and then tell the tree to scroll to that actual item. Then it won’t matter where in the tree the item now exists (if the data structure has changed significantly).

    First save the current item by some criteria:

    item = treeWidget.currentItem() # one way
    item = treeWidget.itemAt(centerOfTree) # another way
    
    # either save the text value or whatever the custom 
    # identifying value is of your item
    text = item.text()
    

    Once you have that data value, be it the text value or some other custom data value, you can repopulate your tree, then look up that item again.

    # this is assuming the item is both present, 
    # and referencing it by its string value
    newItem = treeWidget.findItems(text)[0]
    treeWidget.scrollToItem(newItem)
    

    You can modify this to suit your actual type of items. You may be storing some other custom value on the items to find them again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to populate a QTreeWidget with items (or children of items) that may
I have a QTreeWidget that I insert items in, and the user can select
I have a QTreeWidget which uses the QAbstractItemView.ExtendedSelection property, allowing users to shift click
I have a Qt application that contains a QTreeWidget. I want to replace one
I have an inherited QTreeWidget (called PackList) class and its parent is a KXmlGuiWindow.
Is it possible to have individual indentation of items in a QTreeWidget? In specific,
In my qt app I have this object, filled before setting up my QTreeWidget's
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
I have two columns in a QTreeWidget , one column represents a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.