本文整理汇总了C++中QTreeWidget::addTopLevelItems方法的典型用法代码示例。如果您正苦于以下问题:C++ QTreeWidget::addTopLevelItems方法的具体用法?C++ QTreeWidget::addTopLevelItems怎么用?C++ QTreeWidget::addTopLevelItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget::addTopLevelItems方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QWidget
QWidget *CommandLineAboutPage::createPage(QWidget *parent)
{
QWidget *w = new QWidget(parent);
QVBoxLayout *layout = new QVBoxLayout(w);
layout->setSpacing(0);
layout->setMargin(0);
QTreeWidget *tree = new QTreeWidget(w);
tree->setColumnCount(2);
layout->addWidget(tree);
QFont bold;
bold.setBold(true);
const QString &defaultValue = tkTr(Trans::Constants::UNDEFINED);
QList<QTreeWidgetItem *> defined, undefined;
for(int i=0; i< Core::ICommandLine::MaxParam; ++i) {
const QString &name = CoreImpl::instance()->commandLine()->paramName(i);
const QString &value = CoreImpl::instance()->commandLine()->value(i, defaultValue).toString();
if (!name.isEmpty()) {
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << name << value);
if (value != defaultValue) {
item->setFont(0, bold);
defined << item;
} else {
item->setForeground(0, QBrush(QColor("lightgray")));
item->setForeground(1, QBrush(QColor("lightgray")));
undefined << item;
}
}
}
tree->addTopLevelItems(defined);
tree->sortItems(0, Qt::AscendingOrder);
tree->addTopLevelItems(undefined);
tree->resizeColumnToContents(0);
tree->resizeColumnToContents(1);
return w;
}
示例2: load
void ImporterWizard::load(ObjImporter::SceneInfo& si)
{
QTreeWidget* t = m_ui->tree;
t->clear();
QList<QTreeWidgetItem*> items;
m_objects = new QTreeWidgetItem(t, QStringList() << "Objects");
m_models = new QTreeWidgetItem(t, QStringList() << "Models");
m_animations = new QTreeWidgetItem(t, QStringList() << "Animations");
m_cameras = new QTreeWidgetItem(t, QStringList() << "Cameras");
m_lights = new QTreeWidgetItem(t, QStringList() << "Lights");
m_materials = new QTreeWidgetItem(t, QStringList() << "Materials");
m_textures = new QTreeWidgetItem(t, QStringList() << "Textures");
items << m_objects << m_models << m_animations << m_cameras << m_lights << m_materials << m_textures;
t->addTopLevelItems(items);
QMap<QString, QString>::const_iterator it;
for (it = si.objects.begin(); it != si.objects.end(); ++it) {
newItem(m_objects, it);
newItem(m_models, it);
}
for (it = si.animations.begin(); it != si.animations.end(); ++it) {
QTreeWidgetItem* x = newItem(m_animations, it);
x->setCheckState(0, Qt::Unchecked);
x->setDisabled(true);
}
for (it = si.cameras.begin(); it != si.cameras.end(); ++it) {
QTreeWidgetItem* x = newItem(m_animations, it);
x->setCheckState(0, Qt::Unchecked);
x->setDisabled(true);
}
for (it = si.lights.begin(); it != si.lights.end(); ++it) {
QTreeWidgetItem* x = newItem(m_lights, it);
x->setCheckState(0, Qt::Unchecked);
x->setDisabled(true);
}
for (it = si.materials.begin(); it != si.materials.end(); ++it) {
newItem(m_materials, it);
}
for (it = si.textures.begin(); it != si.textures.end(); ++it) {
newItem(m_textures, it);
}
foreach (QTreeWidgetItem* i, items) {
i->setFirstColumnSpanned(true);
i->setExpanded(true);
if (i->childCount() == 0) i->setDisabled(true);
}
示例3: wrapping
void tst_treeviewfind::wrapping()
{
// set up tree
// search for FOO in
// * HEADER1
// * FOO1
// * HEADER2
// * A
// * HEADER3
// * FOO2
QTreeWidget *tree = new QTreeWidget;
tree->setColumnCount(1);
QList<QTreeWidgetItem *> toplevelitems;
QTreeWidgetItem *item;
item = new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("HEADER1"));
item->addChild(new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("FOO1")));
toplevelitems << item;
item = new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("HEADER2"));
item->addChild(new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("A")));
toplevelitems << item;
item = new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("HEADER3"));
item->addChild(new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("FOO2")));
toplevelitems << item;
tree->addTopLevelItems(toplevelitems);
// set up
Core::ItemViewFind *findSupport = new Core::ItemViewFind(tree);
tree->setCurrentItem(toplevelitems.at(2)->child(0));
QCOMPARE(tree->currentItem()->text(0), QString::fromLatin1("FOO2"));
// forward
findSupport->findStep(QLatin1String("FOO"), 0);
QCOMPARE(tree->currentItem(), toplevelitems.at(0)->child(0));
// backward
tree->setCurrentItem(toplevelitems.at(0)->child(0));
QCOMPARE(tree->currentItem()->text(0), QString::fromLatin1("FOO1"));
findSupport->findStep(QLatin1String("FOO"), Core::FindBackward);
QCOMPARE(tree->currentItem(), toplevelitems.at(2)->child(0));
// clean up
delete findSupport;
delete tree;
}
示例4: columns
void tst_treeviewfind::columns()
{
// set up tree
// search for FOO in
// * HEADER1 | HEADER1
// * FOO1 | A
// * HEADER2 | FOOHEADER2
// * FOO2 | FOO3
// * HEADER3 | HEADER2
// * A | FOO4
QTreeWidget *tree = new QTreeWidget;
tree->setColumnCount(2);
QList<QTreeWidgetItem *> toplevelitems;
QTreeWidgetItem *item;
item = new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("HEADER1") << QLatin1String("HEADER1"));
item->addChild(new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("FOO1") << QLatin1String("A")));
toplevelitems << item;
item = new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("HEADER2") << QLatin1String("FOOHEADER2"));
item->addChild(new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("FOO2") << QLatin1String("FOO3")));
toplevelitems << item;
item = new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("HEADER3") << QLatin1String("HEADER3"));
item->addChild(new QTreeWidgetItem((QTreeWidget *)0, QStringList() << QLatin1String("A") << QLatin1String("FOO4")));
toplevelitems << item;
tree->addTopLevelItems(toplevelitems);
// set up
Core::ItemViewFind *findSupport = new Core::ItemViewFind(tree);
tree->setCurrentItem(toplevelitems.at(0));
QCOMPARE(tree->currentItem()->text(0), QString::fromLatin1("HEADER1"));
// find in first column
findSupport->findStep(QLatin1String("FOO"), 0);
QCOMPARE(tree->currentItem(), toplevelitems.at(0)->child(0));
// find in second column of node with children
findSupport->findStep(QLatin1String("FOO"), 0);
QCOMPARE(tree->currentItem(), toplevelitems.at(1));
// again find in first column
findSupport->findStep(QLatin1String("FOO"), 0);
QCOMPARE(tree->currentItem(), toplevelitems.at(1)->child(0));
// don't stay in item if multiple columns match, and find in second column
findSupport->findStep(QLatin1String("FOO"), 0);
QCOMPARE(tree->currentItem(), toplevelitems.at(2)->child(0));
// wrap
findSupport->findStep(QLatin1String("FOO"), 0);
QCOMPARE(tree->currentItem(), toplevelitems.at(0)->child(0));
// backwards
tree->setCurrentItem(toplevelitems.at(2)->child(0));
QCOMPARE(tree->currentItem()->text(0), QString::fromLatin1("A"));
findSupport->findStep(QLatin1String("FOO"), Core::FindBackward);
QCOMPARE(tree->currentItem(), toplevelitems.at(1)->child(0));
findSupport->findStep(QLatin1String("FOO"), Core::FindBackward);
QCOMPARE(tree->currentItem(), toplevelitems.at(1));
findSupport->findStep(QLatin1String("FOO"), Core::FindBackward);
QCOMPARE(tree->currentItem(), toplevelitems.at(0)->child(0));
findSupport->findStep(QLatin1String("FOO"), Core::FindBackward);
QCOMPARE(tree->currentItem(), toplevelitems.at(2)->child(0));
// clean up
delete findSupport;
delete tree;
}