Sounds good, but it does not seem to do the trick. I have added this method call to paintEvent():
But it still gets painted below the other widgets, not on top. See this Screenshot: http://img156.imageshack.us/img156/3...picturedf4.png
Sounds good, but it does not seem to do the trick. I have added this method call to paintEvent():
But it still gets painted below the other widgets, not on top. See this Screenshot: http://img156.imageshack.us/img156/3...picturedf4.png
You don't want to do that during every single paint event. It would only cause unnecessary overhead.
Children are always on top of their parent. From the attached screenshot it's impossible to see which widget is a children of which parent. So what are MyClass and textDisplay? You are raising textDisplay but MyClass actually draws the text?But it still gets painted below the other widgets, not on top. See this Screenshot: http://img156.imageshack.us/img156/3...picturedf4.png
J-P Nurmi
Okay, but where do I call raise()? Within the constructor?
The QLabel textDisplay is a member of MyClass. In the constructor of MyClass, I create the widgets that are shown as black in the screenshot (Bus, Prozessor etc.) and arrange them in a layout. So that makes them child widgets - right? The textDisplay is not integrated into the layout.Children are always on top of their parent. From the attached screenshot it's impossible to see which widget is a children of which parent. So what are MyClass and textDisplay? You are raising textDisplay but MyClass actually draws the text?
The one widget that is supposed to move around is textDisplay, so it is the only one that gets drawn in the paintEvent() method.
Yeah, it's enough change the stacking order once. Somewhere near creating the widgets is fine.
So if MyClass is the parent, anything it draws (the red text) appears below it's children. Each widget is responsible for drawing itself when it receives a paint event. You don't paint other widgets, like children in the paintEvent() of the parent. Where is the textDisplay widget in the screenshot? Maybe you have to call QWidget::adjustSize() or something to make it adjust it's size to correspond it's contents (this would be done automatically if it was in a layout).The QLabel textDisplay is a member of MyClass. In the constructor of MyClass, I create the widgets that are shown as black in the screenshot (Bus, Prozessor etc.) and arrange them in a layout. So that makes them child widgets - right? The textDisplay is not integrated into the layout.
The one widget that is supposed to move around is textDisplay, so it is the only one that gets drawn in the paintEvent() method.
J-P Nurmi
It's the big red letters :-)
I somehow fear that moving around a widget that is part of a layout will break the layout, no? I will try it out now.Maybe you have to call QWidget::adjustSize() or something to make it adjust it's size to correspond it's contents (this would be done automatically if it was in a layout).
J-P Nurmi
Could you please do somewhere in MyClass after creating all the labels and other child widgets:
and paste the output?
J-P Nurmi
Okay I'm not sure if I came across clearly. I have made another screenshot and this time, I have changed all the German words to English for better understanding. Also, the first time around I did not show all of the windows that my application so far has. Here is the new and complete screenshot:
http://img502.imageshack.us/img502/4...icture2nf4.png
As you can see, the red text could really be anything. Anything you type in. It could also be another color if you want to. In any case, I definitely need it to be freely movable. Up, down, left, right, you name it. So it cannot be part of a layout, as it seems. All the other widgets - Memory, CPU, I/O Unit, Bus, Arrows - however can and in fact, are.
Now, the problem remains: How can I achieve it so that the QLabel gets drawn on top of the other widgets? Calling raise() did not lead to success so far.
Also,
Would the output of that command happen to be found in the directory which is named "debug"? Then I fear that my Qt library is maybe not compiled for debugging, because that directory is empty always.
No, I was referring to the debug output. IDEs tend to show the debug output. If you're not using any IDE, on Windows you will have to add
in the .pro file, regenerate makefile and rebuild the application. An external console is launched together with the application from which you can see the debug output. Alternatively, you can use such utilities as DebugView to monitor the debug output.CONFIG += console
J-P Nurmi
I dont know whether I understood your problem correctly. When you move QLabel, do you want it to be seen at top of other widgets. i.e whenever QLabel has a mouse on it, QLabel should be seen at top of other widgets. If that is what you are looking for then have a look at Examples->QWidgets->ToolTips. Might help.
Thanks
I want this QLabel to be in front of the other QWidgets all of the time.
I think my problem boils down to this: If you have two QWidgets that overlap, how do you control which one of the two is in the foreground? This seems to be complicated by the fact that the one QWidget (the QLabel which must be freely movable) is not part of a layout, while the other QWidgets (which are supposed to be visible, but "behind" the moving QLabel) are.i.e whenever QLabel has a mouse on it, QLabel should be seen at top of other widgets. If that is what you are looking for then have a look at Examples->QWidgets->ToolTips. Might help.
No, re-compiling Qt is not necessary. Sorry, I have no idea what's the problem with no text appearing, though. Did you clean and rebuild the whole project?
It's all about parenting widgets correctly.The order of sibling child widgets can be changed with raise() and lower() as mentioned in the beginning of the thread.
Edit: This is why I asked for dumpObjectTree() output. It will show the actual hierarchy of the object tree.
J-P Nurmi
Last edited by Mister_Crac; 4th May 2007 at 16:51.
Bookmarks