21

I want a widget like the properties window in Visual Studio or NetBeans. It basically has two columns: the name of the property on the left, and the value on the right. The value needs to be able to be restricted to certain types, like 'bool' or 'float' (with valid ranges), but should also support more complex types (perhaps requiring a popup dialog when clicked, and then it can just display a toString() version in the window. I'm sure I can add most of those features myself, but what's the best base widget to start with?

Oh... grouping of properties is good too (like a tree I guess). And property editing should invoke a callback (send a signal).

mpen
  • 272,448
  • 266
  • 850
  • 1,236

3 Answers3

7

Qt designer has properties exactly like you want. They are most likely implemented with QTreeView. You can always look at the source code.

qt designer

Bart
  • 19,692
  • 7
  • 68
  • 77
Eugene
  • 7,180
  • 1
  • 29
  • 36
  • 5
    You mean that's part of the Qt Designer program? Which is open source? Not sure I want to dig through such a massive program. I just need a simple example to look at >. – mpen Aug 18 '09 at 05:45
5

QTreeView or QTableView. Do all (ok, most) of the heavy lifting with a specialized model that handles all of your type restrictions and what-not. Check out delegates as well.

jesterjunk
  • 2,342
  • 22
  • 18
Steve S
  • 5,256
  • 1
  • 29
  • 26
  • Hmm but how would the model tell the QTreeView to render a QSpinBox? – paulm Apr 22 '14 at 12:21
  • Isn't this the same as setItemWidget? The docs say to avoid using that and use a deletgate yet the model seems to use the same methods of displaying widgets? – paulm Apr 22 '14 at 16:19
  • @paulm: I'm confused. Do you mean that you don't see a significant difference between delegates and setItemWidget? – Steve S Apr 22 '14 at 16:45
  • QTreeWidget::setItemWidget docs say "This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QItemDelegate instead." But it appears that QAbstractItemDelegate::createEditor will result in a call to QTreeWidget::setItemWidget for "dynamic" content, so not sure why it has this warning? – paulm Apr 23 '14 at 00:29
  • @paulm: What are you basing that on? setItemWidget() is a non-virtual method of QTreeWidget, but QAbstractItemDelegate works with any QAbstractItemView. Also, note that the docs are telling you to use an entirely different class: QTreeView instead of QTreeWidget. – Steve S Apr 23 '14 at 02:15
  • I've been able to create a really fancy object browser using QTreeWidget and it works perfectly fine with ::setItemWidget. I don't know why Qt advises against it, but for me it works beautifully. – santahopar Aug 14 '18 at 22:59
3

Here's a link led to github, it might be useful.

enter image description here

another userful link

Tom
  • 99
  • 7