简体   繁体   中英

How to create a template widget class with Qt Designer?

My goal is to create two widgets for editing histogram plots (1D and 2D). They are both composed of several standard widgets (sliders, spin boxes, buttons and so on) and the actual plot widget. Except for the plot widget they are completely identical. I thought it would be best to create a template class with the plot widget class as template parameter, in order to avoid code duplication.

The problem now is: I'd like to be able to build/modify this editor widget with Qt Designer. But I can't think of a way to achieve this.

Do you have any idea if this is possible?

I'd prefer not having to put together this widget in pure C++ code...

First and foremost - Q_OBJECT and templates do not blend. At least you definitely cannot use template parameters and Q_OBJECT macro in the same class.

As for your question - I usually place a placeholder widget on the parent's layout and place the interchangeable widget on it during runtime. Sure, it's not "edit in the designer", but this works for me very well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM