Drawing Transparent Control on panel Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Drawing Transparent Control on panel

Post by sivaranjani » Thu Oct 01, 2020 3:07 pm

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

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing Transparent Control on panel

Post by doublemax » Thu Oct 01, 2020 3:11 pm

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?
Use the source, Luke!

sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Re: Drawing Transparent Control on panel

Post by sivaranjani » Thu Oct 01, 2020 3:18 pm

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

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing Transparent Control on panel

Post by doublemax » Thu Oct 01, 2020 3:20 pm

I need to draw rectangle on top of wxControl(eg: wxButton) which will be on panel.
Sorry, that's impossible.
Use the source, Luke!

sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Re: Drawing Transparent Control on panel

Post by sivaranjani » Thu Oct 01, 2020 3:23 pm

Is it impossible to draw on panel or in on top of wxControl?
Can You give some information on this?

Thanks,
Sivaranjani

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing Transparent Control on panel

Post by doublemax » Thu Oct 01, 2020 3:33 pm

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.
Use the source, Luke!

sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Re: Drawing Transparent Control on panel

Post by sivaranjani » Thu Oct 01, 2020 3:52 pm

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.
Attachments
img.PNG
img.PNG (9.21 KiB) Viewed 580 times

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing Transparent Control on panel

Post by doublemax » Thu Oct 01, 2020 4:20 pm

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.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4540
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Drawing Transparent Control on panel

Post by ONEEYEMAN » Thu Oct 01, 2020 9:01 pm

Hi,
Or maybe some kind of a "baloon".

Thank you.

sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Re: Drawing Transparent Control on panel

Post by sivaranjani » Fri Oct 02, 2020 6:37 am

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.

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing Transparent Control on panel

Post by doublemax » Fri Oct 02, 2020 7:03 am

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.
Use the source, Luke!

sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Re: Drawing Transparent Control on panel

Post by sivaranjani » Wed Oct 14, 2020 3:10 am

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

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing Transparent Control on panel

Post by doublemax » Wed Oct 14, 2020 6:02 am

Use wxTreeCtrl::GetBoundingRect to get the rectangle of the item. Pass the tree control itself and this rect to the Showfor() call.
Use the source, Luke!

sivaranjani
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Mar 14, 2018 10:43 am

Re: Drawing Transparent Control on panel

Post by sivaranjani » Wed Oct 14, 2020 1:19 pm

Hi,
Worked as expected. Thank you

Thanks,
ranjani

Post Reply