<?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[SOLVED - QGraphicsObject zValue Apparently Ignored After Window Resized]]></title><description><![CDATA[<p dir="auto">I am currently working on a simple data plotting widget. For my x and y axes I'm displaying ranges of data currently displayed. So for the y axis with 100 items labeled item1 - item100, there are 2 QGraphicsObjects. The top object shows "item1" and "item50", the bottom shows "item51" and "item100". Here is a screen shot:</p>
<p dir="auto">!<a href="http://stalagmite.us/qtHelpImgs/yAxis.PNG" target="_blank" rel="noopener noreferrer nofollow ugc">http://stalagmite.us/qtHelpImgs/yAxis.PNG</a>(yAxis before hover)!</p>
<p dir="auto">As you can see, the top text is too long to fit in the axis. I would like to allow the user to hover the mouse over a range and have that range display on top of all other items in the plot. This functionality is working to some extent. Here is a screen shot:</p>
<p dir="auto">!<a href="http://stalagmite.us/qtHelpImgs/yAxis_hovered.PNG" target="_blank" rel="noopener noreferrer nofollow ugc">http://stalagmite.us/qtHelpImgs/yAxis_hovered.PNG</a>(yAxis during hover)!</p>
<p dir="auto">The problem is that if the main window is maximized then hovering does not bring the range object to the front. Resizing the window by dragging the edges sometimes results in the same.</p>
<p dir="auto">On hovering over range items on the y axis, I set the objects zValue to a high number. The code for this is in the paint method of graphicsVRangeItem.cpp.</p>
<p dir="auto">Relevant code is listed below. The code for SDVGraphicsAbstractRangeItem is not listed as it only has basic data which both SDVGraphicsHRangeItem and SDVGraphicsVRangeItem use.</p>
<p dir="auto">Any help would be appreciated.</p>
]]></description><link>https://forum.qt.io/topic/31940/solved-qgraphicsobject-zvalue-apparently-ignored-after-window-resized</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 10:47:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/31940.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Sep 2013 21:49:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SOLVED - QGraphicsObject zValue Apparently Ignored After Window Resized on Mon, 16 Sep 2013 21:32:43 GMT]]></title><description><![CDATA[<p dir="auto">I tried setting the zValue of the SDVGraphicsAxisItem to a high value and that appears to have fixed my problem.</p>
]]></description><link>https://forum.qt.io/post/195504</link><guid isPermaLink="true">https://forum.qt.io/post/195504</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 16 Sep 2013 21:32:43 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - QGraphicsObject zValue Apparently Ignored After Window Resized on Fri, 13 Sep 2013 21:49:44 GMT]]></title><description><![CDATA[<p dir="auto">graphicsAxisItem.cpp<br />
@<br />
SDVGraphicsAxisItem::SDVGraphicsAxisItem(QGraphicsItem* parent) : QGraphicsObject(parent)<br />
{<br />
sdvTableModel = NULL;<br />
width = height = 10;<br />
lowRange = highRange = NULL;<br />
axisMidIndex = 0;<br />
setAcceptHoverEvents(true);<br />
}</p>
<p dir="auto">SDVGraphicsAxisItem::~SDVGraphicsAxisItem()<br />
{<br />
}</p>
<p dir="auto">QRectF SDVGraphicsAxisItem::boundingRect() const<br />
{<br />
return QRectF(0, 0, width, height);<br />
}</p>
<p dir="auto">void SDVGraphicsAxisItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)<br />
{<br />
QRectF rect = boundingRect();<br />
painter-&gt;fillRect(rect, Qt::white);<br />
}</p>
<p dir="auto">void SDVGraphicsAxisItem::setModel(const SDVTableModel* sdvTableModel)<br />
{<br />
this-&gt;sdvTableModel = sdvTableModel;<br />
QVector&lt;QString&gt; channelNames;<br />
QVector&lt;QDateTime&gt; timestamps;</p>
<p dir="auto">if (sdvTableModel) {<br />
if (axis == Y_Axis) {<br />
channelNames = sdvTableModel-&gt;getChannelNames();<br />
axisMidIndex = channelNames.size() * 0.5;</p>
<p dir="auto">if (!lowRange) {<br />
lowRange = new SDVGraphicsVRangeItem(this);<br />
lowRange-&gt;setMinIndex(0);<br />
lowRange-&gt;setMinText(channelNames[0]);<br />
lowRange-&gt;setMaxIndex(axisMidIndex);<br />
lowRange-&gt;setMaxText(channelNames[axisMidIndex]);<br />
}<br />
lowRange-&gt;setWidth(boundingRect().width());<br />
lowRange-&gt;setHeight(boundingRect().height() * 0.5);</p>
<p dir="auto">if (!highRange) {<br />
highRange = new SDVGraphicsVRangeItem(this);<br />
highRange-&gt;setMinIndex(axisMidIndex + 1);<br />
highRange-&gt;setMinText(channelNames[highRange-&gt;getMinIndex()]);<br />
highRange-&gt;setMaxIndex(channelNames.size() - 1);<br />
highRange-&gt;setMaxText(channelNames[highRange-&gt;getMaxIndex()]);<br />
}<br />
highRange-&gt;setWidth(boundingRect().width());<br />
highRange-&gt;setHeight(boundingRect().height() * 0.5);<br />
highRange-&gt;setY(boundingRect().height() * 0.5);<br />
} else if (axis == X_Axis) {<br />
timestamps = sdvTableModel-&gt;getTimestamps();<br />
axisMidIndex = timestamps.size() * 0.5;</p>
<p dir="auto">if (!lowRange) {<br />
lowRange = new SDVGraphicsHRangeItem(this);<br />
lowRange-&gt;setMinIndex(0);<br />
lowRange-&gt;setMinText(timestamps[0].toString("MM.dd.yy hh:mm:ss.z"));<br />
lowRange-&gt;setMaxIndex(axisMidIndex);<br />
lowRange-&gt;setMaxText(timestamps[axisMidIndex].toString("MM.dd.yy hh:mm:ss.z"));<br />
}<br />
lowRange-&gt;setWidth(boundingRect().width() * 0.5);<br />
lowRange-&gt;setHeight(boundingRect().height());</p>
<p dir="auto">if (!highRange) {<br />
highRange = new SDVGraphicsHRangeItem(this);<br />
highRange-&gt;setMinIndex(axisMidIndex + 1);<br />
highRange-&gt;setMinText(timestamps[highRange-&gt;getMinIndex()].toString("MM.dd.yy hh:mm:ss.z"));<br />
highRange-&gt;setMaxIndex(timestamps.size() - 1);<br />
highRange-&gt;setMaxText(timestamps[highRange-&gt;getMaxIndex()].toString("MM.dd.yy hh:mm:ss.z"));<br />
}<br />
highRange-&gt;setWidth(boundingRect().width() * 0.5);<br />
highRange-&gt;setHeight(boundingRect().height());<br />
highRange-&gt;setX(boundingRect().width() * 0.5);<br />
}<br />
}<br />
}</p>
<p dir="auto">void SDVGraphicsAxisItem::setAxis(AxisItemAxis axis)<br />
{<br />
this-&gt;axis = axis;<br />
}</p>
<p dir="auto">void SDVGraphicsAxisItem::setWidth(double width)<br />
{<br />
this-&gt;width = width;<br />
}</p>
<p dir="auto">void SDVGraphicsAxisItem::setHeight(double height)<br />
{<br />
this-&gt;height = height;<br />
}</p>
<p dir="auto">void SDVGraphicsAxisItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)<br />
{<br />
QGraphicsObject::hoverEnterEvent(event);<br />
}<br />
@</p>
<p dir="auto">graphicsVRangeItem.h<br />
@<br />
class SDVGraphicsVRangeItem : public SDVGraphicsAbstractRangeItem<br />
{<br />
public:<br />
SDVGraphicsVRangeItem(QGraphicsItem* parent = 0);</p>
<p dir="auto">// Paints rectangle from boundingRect() with minText and maxText on the top and bottom respectively<br />
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);</p>
<p dir="auto">protected:<br />
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);<br />
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);</p>
<p dir="auto">private:<br />
QPixmap topLabel;<br />
QPixmap bottomLabel;<br />
QTextOption textOpt;<br />
QPainter topLblPainter;<br />
QPainter botLblPainter;<br />
bool hovered;<br />
int origZValue;<br />
};<br />
@</p>
<p dir="auto">graphicsVRangeItem.cpp<br />
@<br />
SDVGraphicsVRangeItem::SDVGraphicsVRangeItem(QGraphicsItem* parent) : SDVGraphicsAbstractRangeItem(parent)<br />
{<br />
setAcceptHoverEvents(true);<br />
hovered = false;<br />
setFlags(ItemIsMovable);<br />
origZValue = zValue();<br />
}</p>
<p dir="auto">void SDVGraphicsVRangeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)<br />
{<br />
QRectF rect = boundingRect();<br />
topLabel = QPixmap(rect.width(), rect.height() * 0.5);<br />
bottomLabel = QPixmap(rect.width(), rect.height() * 0.5);<br />
Qt::GlobalColor color = Qt::white;<br />
int hoveredWidth;</p>
<p dir="auto">if (hovered) {<br />
setZValue(std::numeric_limits&lt;int&gt;::max());<br />
hoveredWidth = qMax(painter-&gt;fontMetrics().boundingRect(getMinText()).width(), painter-&gt;fontMetrics().boundingRect(getMaxText()).width());<br />
rect.setWidth(hoveredWidth);<br />
topLabel = QPixmap(hoveredWidth, rect.height() * 0.5);<br />
bottomLabel = QPixmap(hoveredWidth, rect.height() * 0.5);<br />
} else {<br />
setZValue(origZValue);<br />
}</p>
<p dir="auto">topLblPainter.begin(&amp;topLabel);<br />
botLblPainter.begin(&amp;bottomLabel);<br />
topLblPainter.fillRect(topLabel.rect(), color);<br />
botLblPainter.fillRect(bottomLabel.rect(), color);<br />
topLblPainter.drawText(topLabel.rect(), getMinText());<br />
textOpt.setAlignment(Qt::AlignBottom);<br />
botLblPainter.drawText(bottomLabel.rect(), getMaxText(), textOpt);<br />
topLblPainter.end();<br />
botLblPainter.end();</p>
<p dir="auto">painter-&gt;drawPixmap(0,0, topLabel);<br />
painter-&gt;drawPixmap(0, topLabel.rect().height(), bottomLabel);<br />
painter-&gt;drawRect(rect);<br />
}</p>
<p dir="auto">void SDVGraphicsVRangeItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)<br />
{<br />
hovered = true;<br />
QGraphicsObject::hoverEnterEvent(event);<br />
//update();<br />
}</p>
<p dir="auto">void SDVGraphicsVRangeItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)<br />
{<br />
//update();<br />
hovered = false;<br />
QGraphicsObject::hoverLeaveEvent(event);<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/post/195264</link><guid isPermaLink="true">https://forum.qt.io/post/195264</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Fri, 13 Sep 2013 21:49:44 GMT</pubDate></item></channel></rss>