Tue, 10/21/2008 - 17:37
Hi how can I put text on occ screen? i am using sample qt-occ widget and I tried using QPainter (in paintEvent) to draw text. At first its fine, it draws the text but any change on screen (any dialog opened or any shape drawn) erases the text and I couldn't find a way to draw it back. Thanks for replies
Wed, 10/22/2008 - 11:49
Are you talking about drawing the text in the OpenGl 3D viewer ? If so, I'm not sure if Qt's QPainter can be of any help here - you need to draw *within* the OpenGl context, not *on top* of it.
You can have a look at how Open CASCADE uses fonts to display text.
A few examples:
- AIS_Trihedron that displays X,Y,Z along the axes;
- XCAFPrs_AISObject that displays names of the entities stored in OCAF Document
Wed, 10/22/2008 - 15:19
Thanks, now I can handle texts with Prs3d_Presentation,_TextAspect and _Text classes. But what I want to do is to write something while a shape is highlighted i.e. while cursor is over the shape. How can I do that? Thanks again
Sun, 10/26/2008 - 11:56
Handle(Graphic3d_Structure) hStruct = new Graphic3d_Structure(m_pAISContext->CurrentViewer()->Viewer());
Handle(Graphic3d_Group) pGr1 = new Graphic3d_Group(hStruct);
hGr1->Text(TextBuffer, Graphic3d_Vertex(m_RotPoint.X(), m_RotPoint.Y(), m_RotPoint.Z()), 0.07, 0, Graphic3d_TP_RIGHT, Graphic3d_HTA_CENTER,Graphic3d_VTA_HALF) ;
Visual3d_TransientManager::BeginDraw(m_pV3dView->View(), Standard_False, Standard_True);
What about this? Sorry if there are some mistakes in the code, but it can give you the idea.
Fri, 04/22/2022 - 16:12
I know this topic is very old but that's exactly what I'm trying to do.
Did you find a way to achieve it?
If you have an article or a post on the subject to advise me, I will be grateful to you.
Thanks a lot.
Fri, 04/22/2022 - 16:38
Have you tried displaying AIS_TextLabel?
Fri, 04/22/2022 - 17:08
Yes, I am currently trying to work with it.
I can easily play on its position, color, etc...
But at the moment I don't see how I can modify the text when another of my objects is hovered.
I guess there is something to do around the message (win api), maybe with WM_MOUSEMOVE and cursor position. But if I have to test every point of each object to know if the text has to be set, I think that I lose too many performance.
Fri, 04/22/2022 - 18:28
Create one single static object of AIS_Text label. While hovering on any shape set label location nearest to shape through SetLocation function and set the data you want display on the Ais_label. If no shape under the mouse. Remove the Ais_Text label from the context. To make it invisible.
Mon, 04/25/2022 - 16:51
Thanks to your advice, I finally get what I want.
The way I used:
As you said, only one object of AIS_Textlabel.
I initialize the text with "".
When WM_MOUSEMOVE is triggered, I test if an object is hovered : m_Context->hasDetected().
If so, I get the currently detected object: m_Context->DetectedInteractive();
I look for it in my list object and change my label text accordingly.
Thank you all for your help.
Fri, 04/22/2022 - 16:38
We use Qt with OCC and what we are doing is using QToolTip in the 3d view directly to show temporary info about highlighted objects like this:
QToolTip::showText(QCursor::pos(),"some text to display",view3d_widget_pointer);
The result looks like the attached screenshot.
Wed, 03/15/2023 - 09:31
Hello. Thank you for your input. In PythonOCC, I am trying to make a QToolTip to display some text when I click a sphere that I created in 3D space. The code that I used and the resulting window is attached below. I would greatly appreciate it if you could explain how I can add a QToolTip using PythonOCC to directly show info about a highlighted object, exactly as you showed in your tooltip.png image above. Thank you!