类似于这种:
就是右下角这个框,有属性名字和对应的value编辑。
这个Widget是作为一个QDockWidget被添加到QMainWindow中的。QMainWindow必须要有centralWidget才能添加DockWidget。DockWidget是可以浮动于centralWidget周边(上下左右)的一种Widget。QMainWindow中有addDockWiget这相应的函数添加。
而QDockWidget中可以设置相应的Widget,这个Widget(实际上就是属性编辑浏览窗口。)这个Widget实际上不是Qt Native自带的。而是Qt的解决方案中提供的Widget,也就是别人帮你封装做好了Widget,拿来用就可以了。这个Widget就是QtPropertyBrowser
样例代码:
nodeproperty.h 此类继承了QDockWidget
1 #ifndef NODE_PROPERTY_H 2 #define NODE_PROPERTY_H 3 4 #include <QObject> 5 #include <QDockWidget> 6 #include "diagramitem.h" 7 8 9 QT_BEGIN_NAMESPACE 10 11 class QDockWidget; 12 class QtVariantPropertyManager; 13 class QtProperty; 14 class QtVariantProperty; 15 class QtVariantEditorFactory; 16 class QtTreePropertyBrowser; 17 QT_END_NAMESPACE 18 19 20 class NodePropertyWidget:public QDockWidget 21 { 22 public: 23 24 NodePropertyWidget(DiagramItem::DiagramType type, QWidget* parent = 0); 25 ~NodePropertyWidget(); 26 27 private: 28 void createProcessTreeProperty(); 29 void createDisplayTreeProperty(); 30 void createArrowTreeProperty(); 31 32 private: 33 QtVariantPropertyManager *variantManager; 34 QtProperty *topItem; 35 QtVariantProperty *item; 36 QtVariantEditorFactory *variantFactory; 37 QtTreePropertyBrowser *variantEditor; 38 }; 39 40 41 42 43 #endif
nodeproperty.cpp
1 #include <QDate> 2 #include <QLocale> 3 #include <QDockWidget> 4 #include <QSizePolicy> 5 6 #include "qtpropertymanager.h" 7 #include "qtvariantproperty.h" 8 #include "qttreepropertybrowser.h" 9 10 #include "nodeproperty.h" 11 12 13 14 15 16 NodePropertyWidget::NodePropertyWidget(DiagramItem::DiagramType type, QWidget * parent) :QDockWidget(parent) 17 { 18 19 switch (type) 20 { 21 case DiagramItem::Process: 22 setWindowTitle("Process Property"); 23 setFloating(true); 24 25 setAllowedAreas(Qt::RightDockWidgetArea); 26 setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred); 27 createProcessTreeProperty(); 28 break; 29 case DiagramItem::Display: 30 setWindowTitle("Display Property"); 31 setFloating(true); 32 33 setAllowedAreas(Qt::RightDockWidgetArea); 34 setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred); 35 createDisplayTreeProperty(); 36 break; 37 case DiagramItem::Line: 38 setWindowTitle("Arrow Property"); 39 setFloating(true); 40 41 setAllowedAreas(Qt::RightDockWidgetArea); 42 setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred); 43 createArrowTreeProperty(); 44 break; 45 default: 46 break; 47 } 48 } 49 50 NodePropertyWidget::~NodePropertyWidget() 51 { 52 53 delete variantManager; 54 delete variantFactory; 55 delete variantEditor; 56 } 57 58 59 void NodePropertyWidget::createProcessTreeProperty(){ 60 61 variantManager = new QtVariantPropertyManager(); 62 63 int i = 0; 64 topItem = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), 65 QString::number(i++) + QLatin1String("Process Property")); 66 67 item = variantManager->addProperty(QVariant::Bool, QString::number(i++) + QLatin1String(" Bool Property")); 68 item->setValue(true); 69 topItem->addSubProperty(item); 70 71 item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property")); 72 item->setValue(20); 73 item->setAttribute(QLatin1String("minimum"), 0); 74 item->setAttribute(QLatin1String("maximum"), 100); 75 item->setAttribute(QLatin1String("singleStep"), 10); 76 topItem->addSubProperty(item); 77 78 item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property (ReadOnly)")); 79 item->setValue(20); 80 item->setAttribute(QLatin1String("minimum"), 0); 81 item->setAttribute(QLatin1String("maximum"), 100); 82 item->setAttribute(QLatin1String("singleStep"), 10); 83 item->setAttribute(QLatin1String("readOnly"), true); 84 topItem->addSubProperty(item); 85 86 item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property")); 87 item->setValue(1.2345); 88 item->setAttribute(QLatin1String("singleStep"), 0.1); 89 item->setAttribute(QLatin1String("decimals"), 3); 90 topItem->addSubProperty(item); 91 92 item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property (ReadOnly)")); 93 item->setValue(1.23456); 94 item->setAttribute(QLatin1String("singleStep"), 0.1); 95 item->setAttribute(QLatin1String("decimals"), 5); 96 item->setAttribute(QLatin1String("readOnly"), true); 97 topItem->addSubProperty(item); 98 99 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property")); 100 item->setValue("Value"); 101 topItem->addSubProperty(item); 102 103 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (Password)")); 104 item->setAttribute(QLatin1String("echoMode"), QLineEdit::Password); 105 item->setValue("Password"); 106 topItem->addSubProperty(item); 107 108 // Readonly String Property 109 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (ReadOnly)")); 110 item->setAttribute(QLatin1String("readOnly"), true); 111 item->setValue("readonly text"); 112 topItem->addSubProperty(item); 113 114 item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property")); 115 item->setValue(QDate::currentDate().addDays(2)); 116 topItem->addSubProperty(item); 117 118 item = variantManager->addProperty(QVariant::Time, QString::number(i++) + QLatin1String(" Time Property")); 119 item->setValue(QTime::currentTime()); 120 topItem->addSubProperty(item); 121 122 item = variantManager->addProperty(QVariant::DateTime, QString::number(i++) + QLatin1String(" DateTime Property")); 123 item->setValue(QDateTime::currentDateTime()); 124 topItem->addSubProperty(item); 125 126 item = variantManager->addProperty(QVariant::KeySequence, QString::number(i++) + QLatin1String(" KeySequence Property")); 127 item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q)); 128 topItem->addSubProperty(item); 129 130 item = variantManager->addProperty(QVariant::Char, QString::number(i++) + QLatin1String(" Char Property")); 131 item->setValue(QChar(386)); 132 topItem->addSubProperty(item); 133 134 item = variantManager->addProperty(QVariant::Locale, QString::number(i++) + QLatin1String(" Locale Property")); 135 item->setValue(QLocale(QLocale::Polish, QLocale::Poland)); 136 topItem->addSubProperty(item); 137 138 item = variantManager->addProperty(QVariant::Point, QString::number(i++) + QLatin1String(" Point Property")); 139 item->setValue(QPoint(10, 10)); 140 topItem->addSubProperty(item); 141 142 item = variantManager->addProperty(QVariant::PointF, QString::number(i++) + QLatin1String(" PointF Property")); 143 item->setValue(QPointF(1.2345, -1.23451)); 144 item->setAttribute(QLatin1String("decimals"), 3); 145 topItem->addSubProperty(item); 146 147 item = variantManager->addProperty(QVariant::Size, QString::number(i++) + QLatin1String(" Size Property")); 148 item->setValue(QSize(20, 20)); 149 item->setAttribute(QLatin1String("minimum"), QSize(10, 10)); 150 item->setAttribute(QLatin1String("maximum"), QSize(30, 30)); 151 topItem->addSubProperty(item); 152 153 item = variantManager->addProperty(QVariant::SizeF, QString::number(i++) + QLatin1String(" SizeF Property")); 154 item->setValue(QSizeF(1.2345, 1.2345)); 155 item->setAttribute(QLatin1String("decimals"), 3); 156 item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34)); 157 item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78)); 158 topItem->addSubProperty(item); 159 160 item = variantManager->addProperty(QVariant::Rect, QString::number(i++) + QLatin1String(" Rect Property")); 161 item->setValue(QRect(10, 10, 20, 20)); 162 topItem->addSubProperty(item); 163 item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50)); 164 165 item = variantManager->addProperty(QVariant::RectF, QString::number(i++) + QLatin1String(" RectF Property")); 166 item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345)); 167 topItem->addSubProperty(item); 168 item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50)); 169 item->setAttribute(QLatin1String("decimals"), 3); 170 171 item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), 172 QString::number(i++) + QLatin1String(" Enum Property")); 173 QStringList enumNames; 174 enumNames << "Enum0" << "Enum1" << "Enum2"; 175 item->setAttribute(QLatin1String("enumNames"), enumNames); 176 item->setValue(1); 177 topItem->addSubProperty(item); 178 179 item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(), 180 QString::number(i++) + QLatin1String(" Flag Property")); 181 QStringList flagNames; 182 flagNames << "Flag0" << "Flag1" << "Flag2"; 183 item->setAttribute(QLatin1String("flagNames"), flagNames); 184 item->setValue(5); 185 topItem->addSubProperty(item); 186 187 item = variantManager->addProperty(QVariant::SizePolicy, QString::number(i++) + QLatin1String(" SizePolicy Property")); 188 topItem->addSubProperty(item); 189 190 item = variantManager->addProperty(QVariant::Font, QString::number(i++) + QLatin1String(" Font Property")); 191 topItem->addSubProperty(item); 192 193 item = variantManager->addProperty(QVariant::Cursor, QString::number(i++) + QLatin1String(" Cursor Property")); 194 topItem->addSubProperty(item); 195 196 item = variantManager->addProperty(QVariant::Color, QString::number(i++) + QLatin1String(" Color Property")); 197 topItem->addSubProperty(item); 198 199 variantFactory = new QtVariantEditorFactory(); 200 201 variantEditor = new QtTreePropertyBrowser(); 202 variantEditor->setFactoryForManager(variantManager, variantFactory); 203 variantEditor->addProperty(topItem); 204 variantEditor->setPropertiesWithoutValueMarked(true); 205 variantEditor->setRootIsDecorated(false); 206 207 setWidget(variantEditor); 208 209 //variantEditor->show(); 210 211 } 212 213 void NodePropertyWidget::createDisplayTreeProperty(){ 214 215 variantManager = new QtVariantPropertyManager(); 216 217 int i = 0; 218 topItem = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), 219 QString::number(i++) + QLatin1String(" Display Property")); 220 221 item = variantManager->addProperty(QVariant::Bool, QString::number(i++) + QLatin1String(" Bool Property")); 222 item->setValue(true); 223 topItem->addSubProperty(item); 224 225 item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property")); 226 item->setValue(20); 227 item->setAttribute(QLatin1String("minimum"), 0); 228 item->setAttribute(QLatin1String("maximum"), 100); 229 item->setAttribute(QLatin1String("singleStep"), 10); 230 topItem->addSubProperty(item); 231 232 item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property (ReadOnly)")); 233 item->setValue(20); 234 item->setAttribute(QLatin1String("minimum"), 0); 235 item->setAttribute(QLatin1String("maximum"), 100); 236 item->setAttribute(QLatin1String("singleStep"), 10); 237 item->setAttribute(QLatin1String("readOnly"), true); 238 topItem->addSubProperty(item); 239 240 item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property")); 241 item->setValue(1.2345); 242 item->setAttribute(QLatin1String("singleStep"), 0.1); 243 item->setAttribute(QLatin1String("decimals"), 3); 244 topItem->addSubProperty(item); 245 246 item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property (ReadOnly)")); 247 item->setValue(1.23456); 248 item->setAttribute(QLatin1String("singleStep"), 0.1); 249 item->setAttribute(QLatin1String("decimals"), 5); 250 item->setAttribute(QLatin1String("readOnly"), true); 251 topItem->addSubProperty(item); 252 253 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property")); 254 item->setValue("Value"); 255 topItem->addSubProperty(item); 256 257 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (Password)")); 258 item->setAttribute(QLatin1String("echoMode"), QLineEdit::Password); 259 item->setValue("Password"); 260 topItem->addSubProperty(item); 261 262 // Readonly String Property 263 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (ReadOnly)")); 264 item->setAttribute(QLatin1String("readOnly"), true); 265 item->setValue("readonly text"); 266 topItem->addSubProperty(item); 267 268 item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property")); 269 item->setValue(QDate::currentDate().addDays(2)); 270 topItem->addSubProperty(item); 271 272 item = variantManager->addProperty(QVariant::Time, QString::number(i++) + QLatin1String(" Time Property")); 273 item->setValue(QTime::currentTime()); 274 topItem->addSubProperty(item); 275 276 item = variantManager->addProperty(QVariant::DateTime, QString::number(i++) + QLatin1String(" DateTime Property")); 277 item->setValue(QDateTime::currentDateTime()); 278 topItem->addSubProperty(item); 279 280 item = variantManager->addProperty(QVariant::KeySequence, QString::number(i++) + QLatin1String(" KeySequence Property")); 281 item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q)); 282 topItem->addSubProperty(item); 283 284 item = variantManager->addProperty(QVariant::Char, QString::number(i++) + QLatin1String(" Char Property")); 285 item->setValue(QChar(386)); 286 topItem->addSubProperty(item); 287 288 item = variantManager->addProperty(QVariant::Locale, QString::number(i++) + QLatin1String(" Locale Property")); 289 item->setValue(QLocale(QLocale::Polish, QLocale::Poland)); 290 topItem->addSubProperty(item); 291 292 item = variantManager->addProperty(QVariant::Point, QString::number(i++) + QLatin1String(" Point Property")); 293 item->setValue(QPoint(10, 10)); 294 topItem->addSubProperty(item); 295 296 item = variantManager->addProperty(QVariant::PointF, QString::number(i++) + QLatin1String(" PointF Property")); 297 item->setValue(QPointF(1.2345, -1.23451)); 298 item->setAttribute(QLatin1String("decimals"), 3); 299 topItem->addSubProperty(item); 300 301 item = variantManager->addProperty(QVariant::Size, QString::number(i++) + QLatin1String(" Size Property")); 302 item->setValue(QSize(20, 20)); 303 item->setAttribute(QLatin1String("minimum"), QSize(10, 10)); 304 item->setAttribute(QLatin1String("maximum"), QSize(30, 30)); 305 topItem->addSubProperty(item); 306 307 item = variantManager->addProperty(QVariant::SizeF, QString::number(i++) + QLatin1String(" SizeF Property")); 308 item->setValue(QSizeF(1.2345, 1.2345)); 309 item->setAttribute(QLatin1String("decimals"), 3); 310 item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34)); 311 item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78)); 312 topItem->addSubProperty(item); 313 314 item = variantManager->addProperty(QVariant::Rect, QString::number(i++) + QLatin1String(" Rect Property")); 315 item->setValue(QRect(10, 10, 20, 20)); 316 topItem->addSubProperty(item); 317 item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50)); 318 319 item = variantManager->addProperty(QVariant::RectF, QString::number(i++) + QLatin1String(" RectF Property")); 320 item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345)); 321 topItem->addSubProperty(item); 322 item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50)); 323 item->setAttribute(QLatin1String("decimals"), 3); 324 325 item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), 326 QString::number(i++) + QLatin1String(" Enum Property")); 327 QStringList enumNames; 328 enumNames << "Enum0" << "Enum1" << "Enum2"; 329 item->setAttribute(QLatin1String("enumNames"), enumNames); 330 item->setValue(1); 331 topItem->addSubProperty(item); 332 333 item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(), 334 QString::number(i++) + QLatin1String(" Flag Property")); 335 QStringList flagNames; 336 flagNames << "Flag0" << "Flag1" << "Flag2"; 337 item->setAttribute(QLatin1String("flagNames"), flagNames); 338 item->setValue(5); 339 topItem->addSubProperty(item); 340 341 item = variantManager->addProperty(QVariant::SizePolicy, QString::number(i++) + QLatin1String(" SizePolicy Property")); 342 topItem->addSubProperty(item); 343 344 item = variantManager->addProperty(QVariant::Font, QString::number(i++) + QLatin1String(" Font Property")); 345 topItem->addSubProperty(item); 346 347 item = variantManager->addProperty(QVariant::Cursor, QString::number(i++) + QLatin1String(" Cursor Property")); 348 topItem->addSubProperty(item); 349 350 item = variantManager->addProperty(QVariant::Color, QString::number(i++) + QLatin1String(" Color Property")); 351 topItem->addSubProperty(item); 352 353 variantFactory = new QtVariantEditorFactory(); 354 355 variantEditor = new QtTreePropertyBrowser(); 356 variantEditor->setFactoryForManager(variantManager, variantFactory); 357 variantEditor->addProperty(topItem); 358 variantEditor->setPropertiesWithoutValueMarked(true); 359 variantEditor->setRootIsDecorated(false); 360 361 setWidget(variantEditor); 362 363 //variantEditor->show(); 364 365 } 366 367 void NodePropertyWidget::createArrowTreeProperty(){ 368 369 variantManager = new QtVariantPropertyManager(); 370 371 int i = 0; 372 topItem = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), 373 QString::number(i++) + QLatin1String("Arrow Property")); 374 375 item = variantManager->addProperty(QVariant::Bool, QString::number(i++) + QLatin1String(" Bool Property")); 376 item->setValue(true); 377 topItem->addSubProperty(item); 378 379 item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property")); 380 item->setValue(20); 381 item->setAttribute(QLatin1String("minimum"), 0); 382 item->setAttribute(QLatin1String("maximum"), 100); 383 item->setAttribute(QLatin1String("singleStep"), 10); 384 topItem->addSubProperty(item); 385 386 item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property (ReadOnly)")); 387 item->setValue(20); 388 item->setAttribute(QLatin1String("minimum"), 0); 389 item->setAttribute(QLatin1String("maximum"), 100); 390 item->setAttribute(QLatin1String("singleStep"), 10); 391 item->setAttribute(QLatin1String("readOnly"), true); 392 topItem->addSubProperty(item); 393 394 item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property")); 395 item->setValue(1.2345); 396 item->setAttribute(QLatin1String("singleStep"), 0.1); 397 item->setAttribute(QLatin1String("decimals"), 3); 398 topItem->addSubProperty(item); 399 400 item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property (ReadOnly)")); 401 item->setValue(1.23456); 402 item->setAttribute(QLatin1String("singleStep"), 0.1); 403 item->setAttribute(QLatin1String("decimals"), 5); 404 item->setAttribute(QLatin1String("readOnly"), true); 405 topItem->addSubProperty(item); 406 407 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property")); 408 item->setValue("Value"); 409 topItem->addSubProperty(item); 410 411 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (Password)")); 412 item->setAttribute(QLatin1String("echoMode"), QLineEdit::Password); 413 item->setValue("Password"); 414 topItem->addSubProperty(item); 415 416 // Readonly String Property 417 item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (ReadOnly)")); 418 item->setAttribute(QLatin1String("readOnly"), true); 419 item->setValue("readonly text"); 420 topItem->addSubProperty(item); 421 422 item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property")); 423 item->setValue(QDate::currentDate().addDays(2)); 424 topItem->addSubProperty(item); 425 426 item = variantManager->addProperty(QVariant::Time, QString::number(i++) + QLatin1String(" Time Property")); 427 item->setValue(QTime::currentTime()); 428 topItem->addSubProperty(item); 429 430 item = variantManager->addProperty(QVariant::DateTime, QString::number(i++) + QLatin1String(" DateTime Property")); 431 item->setValue(QDateTime::currentDateTime()); 432 topItem->addSubProperty(item); 433 434 item = variantManager->addProperty(QVariant::KeySequence, QString::number(i++) + QLatin1String(" KeySequence Property")); 435 item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q)); 436 topItem->addSubProperty(item); 437 438 item = variantManager->addProperty(QVariant::Char, QString::number(i++) + QLatin1String(" Char Property")); 439 item->setValue(QChar(386)); 440 topItem->addSubProperty(item); 441 442 item = variantManager->addProperty(QVariant::Locale, QString::number(i++) + QLatin1String(" Locale Property")); 443 item->setValue(QLocale(QLocale::Polish, QLocale::Poland)); 444 topItem->addSubProperty(item); 445 446 item = variantManager->addProperty(QVariant::Point, QString::number(i++) + QLatin1String(" Point Property")); 447 item->setValue(QPoint(10, 10)); 448 topItem->addSubProperty(item); 449 450 item = variantManager->addProperty(QVariant::PointF, QString::number(i++) + QLatin1String(" PointF Property")); 451 item->setValue(QPointF(1.2345, -1.23451)); 452 item->setAttribute(QLatin1String("decimals"), 3); 453 topItem->addSubProperty(item); 454 455 item = variantManager->addProperty(QVariant::Size, QString::number(i++) + QLatin1String(" Size Property")); 456 item->setValue(QSize(20, 20)); 457 item->setAttribute(QLatin1String("minimum"), QSize(10, 10)); 458 item->setAttribute(QLatin1String("maximum"), QSize(30, 30)); 459 topItem->addSubProperty(item); 460 461 item = variantManager->addProperty(QVariant::SizeF, QString::number(i++) + QLatin1String(" SizeF Property")); 462 item->setValue(QSizeF(1.2345, 1.2345)); 463 item->setAttribute(QLatin1String("decimals"), 3); 464 item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34)); 465 item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78)); 466 topItem->addSubProperty(item); 467 468 item = variantManager->addProperty(QVariant::Rect, QString::number(i++) + QLatin1String(" Rect Property")); 469 item->setValue(QRect(10, 10, 20, 20)); 470 topItem->addSubProperty(item); 471 item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50)); 472 473 item = variantManager->addProperty(QVariant::RectF, QString::number(i++) + QLatin1String(" RectF Property")); 474 item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345)); 475 topItem->addSubProperty(item); 476 item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50)); 477 item->setAttribute(QLatin1String("decimals"), 3); 478 479 item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), 480 QString::number(i++) + QLatin1String(" Enum Property")); 481 QStringList enumNames; 482 enumNames << "Enum0" << "Enum1" << "Enum2"; 483 item->setAttribute(QLatin1String("enumNames"), enumNames); 484 item->setValue(1); 485 topItem->addSubProperty(item); 486 487 item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(), 488 QString::number(i++) + QLatin1String(" Flag Property")); 489 QStringList flagNames; 490 flagNames << "Flag0" << "Flag1" << "Flag2"; 491 item->setAttribute(QLatin1String("flagNames"), flagNames); 492 item->setValue(5); 493 topItem->addSubProperty(item); 494 495 item = variantManager->addProperty(QVariant::SizePolicy, QString::number(i++) + QLatin1String(" SizePolicy Property")); 496 topItem->addSubProperty(item); 497 498 item = variantManager->addProperty(QVariant::Font, QString::number(i++) + QLatin1String(" Font Property")); 499 topItem->addSubProperty(item); 500 501 item = variantManager->addProperty(QVariant::Cursor, QString::number(i++) + QLatin1String(" Cursor Property")); 502 topItem->addSubProperty(item); 503 504 item = variantManager->addProperty(QVariant::Color, QString::number(i++) + QLatin1String(" Color Property")); 505 topItem->addSubProperty(item); 506 507 variantFactory = new QtVariantEditorFactory(); 508 509 variantEditor = new QtTreePropertyBrowser(); 510 variantEditor->setFactoryForManager(variantManager, variantFactory); 511 variantEditor->addProperty(topItem); 512 variantEditor->setPropertiesWithoutValueMarked(true); 513 variantEditor->setRootIsDecorated(false); 514 515 setWidget(variantEditor); 516 //variantEditor->show(); 517 518 }
以下的参考中还会给出很多propertybrowser的很多例子
references:
https://github.com/commontk/QtPropertyBrowser