objects in wxwidgets

35 views
Skip to first unread message

Eduard Filipas

unread,
Jul 28, 2021, 7:28:07 AM7/28/21
to wx-users
hi 
im very new to wxWidgets but as far as im reading documentation its only possible to put strings in gui objects ..coming from java ive got spoiled puting plain objects in gui. In javaFX object representation is based on toString() member function which needs to be overloaded for each class. Down side is you can have only one object representation for any object..I presume it would be better if one could "register" member function for gui element representation.

for example i would like to put in comboBoxCTRL.popUpItems = vector<myObject> represented by member function myObject::presentationForCmbCtrl()

is this possible even now ? if not would it be possible in future?

regards
Ed

Vadim Zeitlin

unread,
Jul 28, 2021, 7:50:15 AM7/28/21
to wx-u...@googlegroups.com
On Wed, 28 Jul 2021 04:28:07 -0700 (PDT) Eduard Filipas wrote:

EF> hi
EF> im very new to wxWidgets but as far as im reading documentation its only
EF> possible to put strings in gui objects ..coming from java ive got spoiled
EF> puting plain objects in gui. In javaFX object representation is based on
EF> toString() member function which needs to be overloaded for each class.
EF> Down side is you can have only one object representation for any object..I
EF> presume it would be better if one could "register" member function for gui
EF> element representation.
EF>
EF> for example i would like to put in comboBoxCTRL.popUpItems =
EF> vector<myObject> represented by member function
EF> myObject::presentationForCmbCtrl()
EF>
EF> is this possible even now ? if not would it be possible in future?

What you're looking for is known as "model-view" pattern in the GUI
frameworks and some wx classes (wxGrid, wxDataViewCtrl) do use it. Most of
them, including wxComboBox, don't, however.

If you need something like this, nothing prevents you from doing it in
your own code -- and this is indeed perfectly doable and many wx
applications do something like this. One of the reasons wx doesn't do it is
that there is nothing like Java Object in C++ and you can't assume that all
C++ programs use the same base class for storing their data nor would it be
a good idea to force all of them to use wxObject.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Eduard Filipas

unread,
Jul 28, 2021, 8:04:23 AM7/28/21
to wx-users
hi
thank you for reply..im mostly working with databases which means i've got tons of vectors.. for comboBox means i have to scroll throu my vector and put in wxString and then on user choice find my object in my vector ..since comboBox uses wxString this one could be part of wxObject ..so basicaly if someone wants to use wxString nothing would change for him while even if im only one i could use wxObjects :) i realy dont know if that solution is possible couse i dont know how wxObjects and wxString  are aligned and please if you have any hint or link how can i adjust comboBoxCTRL for my needs i think it would be benefitial for someone else too :)

thank you
ed
sreda, 28. julij 2021 ob 13:50:15 UTC+2 je oseba Vadim Zeitlin napisala:

Vadim Zeitlin

unread,
Jul 28, 2021, 8:07:15 AM7/28/21
to wx-u...@googlegroups.com
On Wed, 28 Jul 2021 05:04:23 -0700 (PDT) Eduard Filipas wrote:

EF> thank you for reply..im mostly working with databases which means i've got
EF> tons of vectors.. for comboBox means i have to scroll throu my vector and
EF> put in wxString and then on user choice find my object in my vector ..since
EF> comboBox uses wxString this one could be part of wxObject ..so basicaly if
EF> someone wants to use wxString nothing would change for him while even if im
EF> only one i could use wxObjects :) i realy dont know if that solution is
EF> possible couse i dont know how wxObjects and wxString are aligned and
EF> please if you have any hint or link how can i adjust comboBoxCTRL for my
EF> needs i think it would be benefitial for someone else too :)

Sorry, this is really not clear at all, but I just want to say that you
shouldn't use wxComboBox for displaying database contents if your tables
can have a lot of rows (meaning more than a couple of hundreds). You should
look into the already mentioned wxDataViewCtrl, wxGrid or maybe wxListCtrl
in virtual mode instead.

Eduard Filipas

unread,
Jul 28, 2021, 8:51:50 AM7/28/21
to wx-users
hi 
no the content of comboBoxCTRL usualy wouldnt have more than 10-20 rows but i would like to have custom popup filled with "model-view" pattern objects thinking now it would be possible to use maps..that generaly i think would save me from modifying comboBoxCTRL ...the problem i see is when new version of wxWidgets comes out i would need to update my custom comboboxctrl.

thank you for helping me find solution :)
ed
sreda, 28. julij 2021 ob 14:07:15 UTC+2 je oseba Vadim Zeitlin napisala:

Vadim Zeitlin

unread,
Jul 28, 2021, 2:46:52 PM7/28/21
to wx-u...@googlegroups.com
On Wed, 28 Jul 2021 05:51:50 -0700 (PDT) Eduard Filipas wrote:

EF> no the content of comboBoxCTRL usualy wouldnt have more than 10-20 rows but
EF> i would like to have custom popup filled with "model-view" pattern objects
EF> thinking now it would be possible to use maps..that generaly i think would
EF> save me from modifying comboBoxCTRL ...the problem i see is when new
EF> version of wxWidgets comes out i would need to update my custom
EF> comboboxctrl.

Sorry, I really don't understand why do you think you would need to modify
anything, but in any case you definitely shouldn't do that. You can use any
of the previously mentioned controls as a popup with wxComboCtrl and you
can fill them with whatever data you have.

I think you probably should try doing what you want to do in order to
narrow down the problem/question you have because right now it's just not
clear at all what it is.
Reply all
Reply to author
Forward
0 new messages