<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to retrieve position of a widget which resides in a scrollarea]]></title><description><![CDATA[<p dir="auto">I have a basic application where there is a scrollarea full of  values such as 0.15, 0.16, 0.17, 0.18 etc.<br />
You can swipe through the scrollarea using QScroller. I want to use the setSnapPositionX (a function of QScroller class) in order to create snap points on the values, indicating the current value . The function needs a list of points to create snap points.  So I want to retrieve the positions of the QLabels inside of the scrollarea(from what I understood, position inside of a scrollarea works sort of different than usual geometry of the widgets) and after retrieving them, I want to set the snap points to those points. The only problem here is I cannot get the positions of the QLabels. When I create a QLabel from the Qt Designer and instantiate it in the code using findChild(), I am able to retrieve the position info of the label, thus, when I compare it using QScroller.finalPosition() function, it is nearly accurate. But I generate the QLabels from the code and when I do so, I could not accomplish to get the widget's position. Here is what I tried:</p>
<pre><code>for i in range(rangeStart,rangeEnd):
            self.lb1 = QLabel("0.{}  ".format(i))
            self.hl.addWidget(self.lb1)
            self.lb1.setObjectName("lb{}".format(i))
            pList.append(self.lb1)
        for widget in pList:
            print(widget.x())
</code></pre>
<p dir="auto">What I basically do here is creating a label, then adding it to the horizontalLayout then also adding it to a list. Lastly, printing the positions of the labels using a for loop. But it gives only zeros. What am I doing wrong?</p>
]]></description><link>https://forum.qt.io/topic/139314/how-to-retrieve-position-of-a-widget-which-resides-in-a-scrollarea</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 20:22:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139314.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Sep 2022 13:11:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to retrieve position of a widget which resides in a scrollarea on Thu, 15 Sep 2022 08:01:52 GMT]]></title><description><![CDATA[<p dir="auto">That worked like  charm, thanks a lot, appreciated!</p>
]]></description><link>https://forum.qt.io/post/728808</link><guid isPermaLink="true">https://forum.qt.io/post/728808</guid><dc:creator><![CDATA[proz goret]]></dc:creator><pubDate>Thu, 15 Sep 2022 08:01:52 GMT</pubDate></item><item><title><![CDATA[Reply to How to retrieve position of a widget which resides in a scrollarea on Wed, 14 Sep 2022 19:23:17 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">You are retrieving the information at the wrong time. Until shown, widgets do not have any "physical presence" hence the values you get.</p>
<p dir="auto">You should trigger this calculation in the show event of that widget.</p>
]]></description><link>https://forum.qt.io/post/728759</link><guid isPermaLink="true">https://forum.qt.io/post/728759</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 14 Sep 2022 19:23:17 GMT</pubDate></item></channel></rss>