ctkTreeComboBoxTest1.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QStandardItemModel>
  17. #include <QTimer>
  18. #include <QTreeView>
  19. // CTK includes
  20. #include "ctkTreeComboBox.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkTreeComboBoxTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. ctkTreeComboBox combo;
  29. QStandardItemModel model;
  30. model.appendRow(new QStandardItem("Test1"));
  31. model.item(0)->appendRow(new QStandardItem("Test1.1"));
  32. model.item(0)->appendRow(new QStandardItem("Test1.2"));
  33. model.item(0)->appendRow(new QStandardItem("Test1.3"));
  34. model.appendRow(new QStandardItem("Test2"));
  35. model.appendRow(new QStandardItem("Test3"));
  36. combo.setModel(&model);
  37. if (combo.treeView() == 0)
  38. {
  39. std::cerr << "No tree view" << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. combo.show();
  43. QApplication::processEvents();
  44. // if the effect UI_AnimateCombo is enabled, the popup doesn't have time
  45. // to be visible when hidePopup() is called wich doesn't hide the popup.
  46. bool oldEnabled = QApplication::isEffectEnabled(Qt::UI_AnimateCombo);
  47. QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
  48. combo.showPopup();
  49. QApplication::processEvents();
  50. combo.treeView()->setExpanded(model.item(0)->index(), true);
  51. QApplication::processEvents();
  52. combo.hidePopup();
  53. QApplication::processEvents();
  54. QApplication::setEffectEnabled(Qt::UI_AnimateCombo, oldEnabled);
  55. combo.showPopup();
  56. if (argc < 2 || QString(argv[1]) != "-I" )
  57. {
  58. QTimer::singleShot(200, &app, SLOT(quit()));
  59. }
  60. return app.exec();
  61. }