Page 1 of 1

Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:07 pm
by sivaranjani
Hi,

Is it possible to draw transparent rectangle and text in wxPanel?
I have tried using wxPaintDc in which drawn rectangle not displayed on screen,
using wxScreenDc rectangle is dispalyed without transparency.

Code: Select all

void Panel::OnPaint(wxPaintEvent &evt)
{
	wxPaintDC dc(this);
	wxGraphicsContext* gdc1 = wxGraphicsContext::Create(dc);
	wxGCDC gdc2;
	gdc2.SetGraphicsContext(gdc1);
	wxDC &gdc = static_cast<wxDC&>(gdc2);
	PrepareDC(gdc);
	int w, h;
	GetSize(&w, &h);
	gdc.SetPen(*wxTRANSPARENT_PEN);
	gdc.SetBrush(*wxRED);
	wxRect rec = GetClientRect();
	gdc.DrawRoundedRectangle(rec, 20);
	gdc.SetTextForeground(wxColour(*wxGREEN));
	gdc.SetFont(wxFontInfo(10).Family(wxFONTFAMILY_MAX).Bold());
	gdc.DrawText("designer panel drawText", 50, 50);
}
Could you Suggest me how this can be drawn?



Thanks,
ranjani

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:11 pm
by doublemax
It's unclear what result you want to achieve.
Is it possible to draw transparent rectangle and text in wxPanel?
Transparent on top of what?

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:18 pm
by sivaranjani
I need to draw rectangle on top of wxControl(eg: wxButton) which will be on panel.
If Rectangle is drawn on top of control panel should be visible below that rectangle

thanks,
ranjani

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:20 pm
by doublemax
I need to draw rectangle on top of wxControl(eg: wxButton) which will be on panel.
Sorry, that's impossible.

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:23 pm
by sivaranjani
Is it impossible to draw on panel or in on top of wxControl?
Can You give some information on this?

Thanks,
Sivaranjani

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:33 pm
by doublemax
You can't draw on top of native controls as they are drawn by the OS and not inside wxWidgets using the "normal" wxPaintDC mechanism. And most controls in wxWidgets are native.

You could theoretically use wxWindowDC to draw onto the control, but there is no event that tells you when to redraw it.

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 3:52 pm
by sivaranjani
ok. Thanks for the quick response.
Is is possible to set transparent window to display text without painting?
Its Something like displaying message for navigation what should be done next.

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 4:20 pm
by doublemax
It it doesn't have to be transparent, i'd use wxRichToolTip for that.
https://docs.wxwidgets.org/trunk/classw ... l_tip.html

Check the "dialogs" sample, under Dialogs -> Rich Tooltip dialog, to see how it looks like and what it can do.

Re: Drawing Transparent Control on panel

Posted: Thu Oct 01, 2020 9:01 pm
by ONEEYEMAN
Hi,
Or maybe some kind of a "baloon".

Thank you.

Re: Drawing Transparent Control on panel

Posted: Fri Oct 02, 2020 6:37 am
by sivaranjani
Hi,

I had used wxRichToolTip it worked as expected. But, Additionally need transparency on richtooltip.
Is there some way to set transparent kind?
Tried using transparent color but displayed in black.

Thanks,
Ranjani.

Re: Drawing Transparent Control on panel

Posted: Fri Oct 02, 2020 7:03 am
by doublemax
I had used wxRichToolTip it worked as expected. But, Additionally need transparency on richtooltip.
Is there some way to set transparent kind?
The only way to do that would be with a separate wxFrame.

Then you could set a non-rectangular shape with wxNonOwnedWindow::SetShape
https://docs.wxwidgets.org/trunk/classw ... 0b55e89613

... and set the transparency with wxWindow::SetTransparent
https://docs.wxwidgets.org/trunk/classw ... 0f45a0656f

However, you can only set the transparency for the whole window, you can't have the background semi-transparent and the texton it opaque. You could fake that by grabbing the screencontent under the window with wxScreenDC and use that as a background for your window.

Re: Drawing Transparent Control on panel

Posted: Wed Oct 14, 2020 3:10 am
by sivaranjani
Hi,
I have used wxrichtool tip to display popup.
Now I am trying to use this in wxTreelistcontrol it will have list of tree item as their childrens.
So to pass as window,typecasted.But is getting crashed when tip.showFor() is executed.

Code: Select all

wxTreeItemId iId = pModeltree->GetTreeItem(iValue);
wxWindowList pWindowList = pModeltree->GetChildren();
wxWindow *pWindowTemp = NULL, *pWindowTemp1 = NULL,*pWindow=NULL;
wxRichToolTip tip("Tool Tip","Message");
for (int i = 0; i < icount; i++)
{
    pWindowTemp = pWindowList[i];
    if (pWindowTemp->IsKindOf(CLASSINFO(wxTreeListCtrl)))
    {
		pWindowTemp = ((wxTreeListCtrl*)pWindowTemp);
               pWindowTemp1 = ((wxTreeListCtrl*)pWindowTemp);
              pWindow= (wxWindow*)((wxTreeListCtrl*)pWindowTemp1)->GetItemData(iId);
              if (pWindow)
	         tip.ShowFor(pWindow);
              break;
    }
}
when treecontrol is passed as window richtool tip dislayed in center.
Is there any way to display richtooltip to wxtreeitem?

Thanks,
ranjani

Re: Drawing Transparent Control on panel

Posted: Wed Oct 14, 2020 6:02 am
by doublemax
Use wxTreeCtrl::GetBoundingRect to get the rectangle of the item. Pass the tree control itself and this rect to the Showfor() call.

Re: Drawing Transparent Control on panel

Posted: Wed Oct 14, 2020 1:19 pm
by sivaranjani
Hi,
Worked as expected. Thank you

Thanks,
ranjani