[wxwidgets] create a complex button

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
User avatar
baert
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Wed Sep 15, 2004 1:52 pm
Location: France - Compiegne-Paris-Lille

[wxwidgets] create a complex button

Post by baert »

Hi,

I am new to wxwindows (I come from Java),

I need to create a complex button, I mean a button which can have several lines, this line containing different kind of objects, for exemple:-
- 1st line: an icon on the left + text on the right
-2nd line: Text in bold + specific color
-3rd line: text (font1) on the left, text font2 on the middel, and another text on the right.

I already developed this kind of button under Java, it was easy because in Java a button contain a Panel, and in a Panel you can do what ever you want (using a specific layout, insert child panels, etc...)

I am shure this can be possible, but I dont know how !

Thanks for your help !

Bart
Bart
caseyodonnell
Knows some wx things
Knows some wx things
Posts: 31
Joined: Fri Sep 10, 2004 1:03 pm
Location: Troy, NY
Contact:

Re: [wxwidgets] create a complex button

Post by caseyodonnell »

Take a look at the implementation for wxBitmapButton...it is a custom button derived from wxButton. Theoretically you can derive from wxButton and have your own custom control.

CKO
baert wrote:I need to create a complex button, I mean a button which can have several lines, this line containing different kind of objects, for exemple:-
- 1st line: an icon on the left + text on the right
-2nd line: Text in bold + specific color
-3rd line: text (font1) on the left, text font2 on the middel, and another text on the right.

I already developed this kind of button under Java, it was easy because in Java a button contain a Panel, and in a Panel you can do what ever you want (using a specific layout, insert child panels, etc...)
User avatar
baert
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Wed Sep 15, 2004 1:52 pm
Location: France - Compiegne-Paris-Lille

Post by baert »

Thanks for your help,

The probleme in my case is that Data are dynamic: I can't put all the data in a fixed bitmap, and display the bitmap.
Text ad Icon on the buttons are dynamic, they can automatially change due to some events.
Bart
caseyodonnell
Knows some wx things
Knows some wx things
Posts: 31
Joined: Fri Sep 10, 2004 1:03 pm
Location: Troy, NY
Contact:

Post by caseyodonnell »

Right. What I meant was that you could use wxBitmapButton as a means to better understanding how to do this. And the bitmaps and text on buttons can be changed dynamically now. No modification needed.
baert wrote:Thanks for your help,

The probleme in my case is that Data are dynamic: I can't put all the data in a fixed bitmap, and display the bitmap.
Text ad Icon on the buttons are dynamic, they can automatially change due to some events.
User avatar
baert
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Wed Sep 15, 2004 1:52 pm
Location: France - Compiegne-Paris-Lille

Post by baert »

you mean, I should look at the implementation of wxBitmapButton ?
I'll try thiis and let you know what I can learn with that !
Bart
caseyodonnell
Knows some wx things
Knows some wx things
Posts: 31
Joined: Fri Sep 10, 2004 1:03 pm
Location: Troy, NY
Contact:

Post by caseyodonnell »

baert wrote:you mean, I should look at the implementation of wxBitmapButton ?
I'll try thiis and let you know what I can learn with that !
Yeah...I was also thinking...

wxButton is a wxWindow, which you can place new elements into. So you could (I think) add a sizer and sub-elements to a wxButton. Should work just fine.

CKO
User avatar
baert
I live to help wx-kind
I live to help wx-kind
Posts: 169
Joined: Wed Sep 15, 2004 1:52 pm
Location: France - Compiegne-Paris-Lille

Post by baert »

I try this method,
yet I added a Sizer and a Panel inside, the button stay empty ....
:roll:
Bart
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

You have to understand where wxWidgets is built on. The wxButton, wxTextCtrl etc are all native components. Which means the wxButton is a wrapper .. since it is a native control you can't really insert something inside a button like a panel or a sizer because the button in Windows cannot be treated that way as well ..

If you want this, you will have to compose your own button from a panel and sizer, and make it look like a button by catching mouse up and down events..

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi »

Jorg wrote:You have to understand where wxWidgets is built on. The wxButton, wxTextCtrl etc are all native components. Which means the wxButton is a wrapper .. since it is a native control you can't really insert something inside a button like a panel or a sizer because the button in Windows cannot be treated that way as well ..

If you want this, you will have to compose your own button from a panel and sizer, and make it look like a button by catching mouse up and down events..

Regards,
- Jorgen
Question, then why is it derived from wxWindow then? Shouldn't a correct way it to derive it only from wxControl (which is derived from wxObject and wxEventHandler)? Surely, the wxControl class would also need to contain more generic methods like Show(), Hide(), Enable(), Disable(), and so on...
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

I guess because it does implement some of the wxWindow based methods like sizing etc. Also, there is one base class needed to add all those elements to a panel or frame. It might have been given some more consideration, but hey MFC also did it like this. CButton was in no way extendible when it was in fact a wrapped control like al wxButton would be :-)

I guess it is common sense for most people who know that the wxButton is a native component, and thus cannot be extended. But I can understand the confusion. Maybe they should at least perform checks in debug mode if people are trying to do "the impossible" ;-)

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Post Reply