I need dozens of combo boxes around my program to śhare one list of item texts.
Currently my combo boxes are wxOwnerDrawnComboBox and I use Append on each of them, so in memory I have same identical list of strings dozens of times. How could I make my combo boxes only use one list of strings to display texts?
I could overwrite the OnDrawItem but I don't want to handle proper font, font size, front and back color etc.
Qt equivalent of what I need is QAbstractListModel.
How to share strings between many combo boxes? Topic is solved
Re: How to share strings between many combo boxes?
Hi,
This is more of the basic C++ questions rather than wxWidgets.
Just create a class whose parent will be wxOwnerDrawComboBox and use it in you program.
Thank you.
This is more of the basic C++ questions rather than wxWidgets.
Just create a class whose parent will be wxOwnerDrawComboBox and use it in you program.
Thank you.
Re: How to share strings between many combo boxes?
-.- very helpful answer
Re: How to share strings between many combo boxes?
wxItemContainer just doesn't support virtual data. If it's really about saving memory (which i doubt), then you could only fill the control with empty strings, override OnDrawItem and then get the "real" string data from another source based on the item number.
As for the drawing, wxRendererNative::DrawItemText() could probably handle most of the dirty work:
http://docs.wxwidgets.org/trunk/classwx ... ac0e53fe3e
As for the drawing, wxRendererNative::DrawItemText() could probably handle most of the dirty work:
http://docs.wxwidgets.org/trunk/classwx ... ac0e53fe3e
Use the source, Luke!
Re: How to share strings between many combo boxes?
Thank you doublemax. So there is no wxListView kind of combo box that lets me tell what to write from a function like OnGetItemText.
I came up with this piece of code where I can write any string and make it look good.
I came up with this piece of code where I can write any string and make it look good.
Code: Select all
void AGEComboBox::OnDrawItem(wxDC &dc, const wxRect &rect, int item, int flags) const
{
wxRendererNative::Get().DrawItemText(const_cast<AGEComboBox*>(this), dc, "Terve", rect, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
}