本文整理汇总了C++中QQuickItem::setParentItem方法的典型用法代码示例。如果您正苦于以下问题:C++ QQuickItem::setParentItem方法的具体用法?C++ QQuickItem::setParentItem怎么用?C++ QQuickItem::setParentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQuickItem
的用法示例。
在下文中一共展示了QQuickItem::setParentItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setInitialState
void QQuickLoaderPrivate::setInitialState(QObject *obj)
{
Q_Q(QQuickLoader);
QQuickItem *item = qmlobject_cast<QQuickItem*>(obj);
if (item) {
// If the item doesn't have an explicit size, but the Loader
// does, then set the item's size now before bindings are
// evaluated, otherwise we will end up resizing the item
// later and triggering any affected bindings/anchors.
if (widthValid && !QQuickItemPrivate::get(item)->widthValid)
item->setWidth(q->width());
if (heightValid && !QQuickItemPrivate::get(item)->heightValid)
item->setHeight(q->height());
item->setParentItem(q);
}
if (obj) {
QQml_setParent_noEvent(itemContext, obj);
QQml_setParent_noEvent(obj, q);
itemContext = 0;
}
if (initialPropertyValues.isUndefined())
return;
QQmlComponentPrivate *d = QQmlComponentPrivate::get(component);
Q_ASSERT(d && d->engine);
QV4::ExecutionEngine *v4 = qmlGlobalForIpv.engine();
Q_ASSERT(v4);
QV4::Scope scope(v4);
QV4::ScopedValue ipv(scope, initialPropertyValues.value());
d->initializeObjectWithInitialProperties(qmlGlobalForIpv, ipv, obj);
}
示例2: qmlContext
QT_BEGIN_NAMESPACE
QQuickItem *QQuickTextUtil::createCursor(
QQmlComponent *component, QQuickItem *parent, const QRectF &rectangle, const char *className)
{
QQuickItem *item = 0;
if (component->isReady()) {
QQmlContext *creationContext = component->creationContext();
if (QObject *object = component->beginCreate(creationContext
? creationContext
: qmlContext(parent))) {
if ((item = qobject_cast<QQuickItem *>(object))) {
QQml_setParent_noEvent(item, parent);
item->setParentItem(parent);
item->setPosition(rectangle.topLeft());
item->setHeight(rectangle.height());
} else {
qmlInfo(parent) << tr("%1 does not support loading non-visual cursor delegates.")
.arg(QString::fromUtf8(className));
}
component->completeCreate();
return item;
}
} else if (component->isLoading()) {
QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
parent, SLOT(createCursor()), Qt::UniqueConnection);
return item;
}
qmlInfo(parent, component->errors()) << tr("Could not load cursor delegate");
return item;
}
示例3: view_full_table
int FloodingRT::view_full_table(QQmlApplicationEngine *engine, QQuickItem *panel)
{
//===============================
//Populate Flooding Routing Table
//===============================
// Check to make sure all vectors are of the same size
if (destination_node_pool.size() != gateway_node_pool.size() ||
gateway_node_pool.size() != weight_pool.size() ||
weight_pool.size() != destination_node_pool.size())
return -1; // return -1 for an error
// Get the iterators for the different vectors
std::vector<Node*>::iterator dest_iter = destination_node_pool.begin();
std::vector<Node*>::iterator gate_iter = gateway_node_pool.begin();
std::vector<int>::iterator weight_iter = weight_pool.begin();
// Creating a QObject for the routing table model, this is where
// all of the items get added to
QQmlComponent comp(engine, QUrl("qrc:/qml_files/flooding_model.qml"));
QObject *object = comp.create();
QQuickItem *model = qobject_cast<QQuickItem*>(object);
/*
// While loop setup - Make sure all iterators are not at the end
while (dest_iter != destination_node_pool.end() &&
gate_iter != gateway_node_pool.end() &&
weight_iter != weight_pool.end())
{
// Grab the reference to the next item in each vector
// This is the information for a row in the routing table
Node *dest = *dest_iter;
Node *gate = *gate_iter;
int weight = *weight_iter;
// Creating the routing table item QObject
QQmlComponent component(engine, QUrl("qrc:/qml_files/flooding_item.qml"));
object = component.create();
QQuickItem *item = qobject_cast<QQuickItem*>(object);
// Setting the properties of the QObject
item->setProperty("destination", dest->get_name());
item->setProperty("gateway", gate->get_name());
item->setProperty("weight", weight);
// Adding the routing table item to the model
item->setParentItem(model);
// Moving the iterators to the next item
dest_iter++;
gate_iter++;
weight_iter++;
}
*/
// Create the routing table to actually be displayed
QQmlComponent comp1(engine, QUrl("qrc:/qml_files/flooding_routing_table.qml"));
QObject *obj = comp1.create();
QQuickItem *routing_table = qobject_cast<QQuickItem*>(obj);
obj->findChild<QObject*>("table");
model->setParentItem(routing_table);
obj->setProperty("model", "flooding_routing_table_model");
// Add the routing table to the main panel for viewing
routing_table->setParentItem(panel);
return 0;
}//end of view_full_table
示例4: QQmlComponent
QQuickItem * DataSetView::createColumnHeader(int col)
{
//std::cout << "createColumnHeader("<<col<<") called!\n" << std::flush;
if(_columnHeaderDelegate == NULL)
{
_columnHeaderDelegate = new QQmlComponent(qmlEngine(this));
_columnHeaderDelegate->setData("import QtQuick 2.10\nItem {\n"
"property alias text: tekst.text\n"
"Rectangle { color: \"lightGrey\"; anchors.fill: parent }\n"
"Text { id: tekst; anchors.centerIn: parent }\n"
"}", QUrl());
}
QQuickItem * columnHeader = NULL;
if(_columnHeaderItems.count(col) == 0 || _columnHeaderItems[col] == NULL)
{
if(_columnHeaderStorage.size() > 0)
{
#ifdef DEBUG_VIEWPORT
std::cout << "createColumnHeader("<<col<<") from storage!\n" << std::flush;
#endif
columnHeader = _columnHeaderStorage.top();
_columnHeaderStorage.pop();
}
else
{
#ifdef DEBUG_VIEWPORT
std::cout << "createColumnHeader("<<col<<") ex nihilo!\n" << std::flush;
#endif
columnHeader = qobject_cast<QQuickItem*>(_columnHeaderDelegate->create());
columnHeader->setParent(this);
columnHeader->setParentItem(this);
}
columnHeader->setProperty("z", 10);
columnHeader->setProperty("text", _model->headerData(col, Qt::Orientation::Horizontal).toString());
columnHeader->setZ(-3);
columnHeader->setHeight(_dataRowsMaxHeight);
columnHeader->setWidth(_dataColsMaxWidth[col]);
columnHeader->setVisible(true);
_columnHeaderItems[col] = columnHeader;
}
else
columnHeader = _columnHeaderItems[col];
columnHeader->setX(_colXPositions[col]);
columnHeader->setY(_viewportY);
return columnHeader;
}
示例5: reparentQmlObject
// qquickviewinspector.cpp::142
void reparentQmlObject(QObject *object, QObject *newParent)
{
if (!newParent)
return;
object->setParent(newParent);
QQuickItem *newParentItem = qobject_cast<QQuickItem*>(newParent);
QQuickItem *item = qobject_cast<QQuickItem*>(object);
if (newParentItem && item)
item->setParentItem(newParentItem);
}
示例6: if
static QQmlPrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent)
{
// When setting a parent (especially during dynamic object creation) in QML,
// also try to set up the analogous item/window relationship.
QQuickItem *parentItem = qmlobject_cast<QQuickItem *>(parent);
if (parentItem) {
QQuickItem *item = qmlobject_cast<QQuickItem *>(obj);
if (item) {
// An Item has another Item
item->setParentItem(parentItem);
return QQmlPrivate::Parented;
} else if (parentItem->window()) {
QQuickWindow *win = qmlobject_cast<QQuickWindow *>(obj);
if (win) {
// A Window inside an Item should be transient for that item's window
win->setTransientParent(parentItem->window());
return QQmlPrivate::Parented;
}
}
return QQmlPrivate::IncompatibleObject;
} else {
QQuickWindow *parentWindow = qmlobject_cast<QQuickWindow *>(parent);
if (parentWindow) {
QQuickWindow *win = qmlobject_cast<QQuickWindow *>(obj);
if (win) {
// A Window inside a Window should be transient for it
win->setTransientParent(parentWindow);
return QQmlPrivate::Parented;
} else {
QQuickItem *item = qmlobject_cast<QQuickItem *>(obj);
if (item) {
// The parent of an Item inside a Window is actually the implicit content Item
item->setParentItem(parentWindow->contentItem());
return QQmlPrivate::Parented;
}
}
return QQmlPrivate::IncompatibleObject;
}
}
return QQmlPrivate::IncompatibleParent;
}
示例7: press_and_hold_node
void Graph::press_and_hold_node(QString node_name)
{
QQmlComponent component(engine, QUrl("qrc:/qml_files/node_dialog.qml"));
QObject *object = component.create();
object->setParent(panel);
QQuickItem *item = qobject_cast<QQuickItem*>(object);
item->setParentItem(qobject_cast<QQuickItem*>(panel));
QObject::connect(object,SIGNAL(destroy_dialog(void)),this,SLOT(destroy_dialog(void)));
if (started && !paused)
this->pause_animation();
Node* node = get_node_by_name(node_name);
}
示例8: ind
QQuickItem * DataSetView::createTextItem(int row, int col)
{
//std::cout << "createTextItem("<<row<<", "<<col<<") called!\n" << std::flush;
if((_cellTextItems.count(col) == 0 && _cellTextItems[col].count(row) == 0) || _cellTextItems[col][row] == NULL)
{
if(_itemDelegate == NULL)
{
_itemDelegate = new QQmlComponent(qmlEngine(this));
_itemDelegate->setData("import QtQuick 2.10\nText { property bool active: true; text: \"???\"; color: active ? 'black' : 'grey' }", QUrl());
}
QQuickItem * textItem = NULL;
if(_textItemStorage.size() > 0)
{
#ifdef DEBUG_VIEWPORT
std::cout << "createTextItem("<<row<<", "<<col<<") from storage!\n" << std::flush;
#endif
textItem = _textItemStorage.top();
_textItemStorage.pop();
}
else
{
#ifdef DEBUG_VIEWPORT
std::cout << "createTextItem("<<row<<", "<<col<<") ex nihilo!\n" << std::flush;
#endif
textItem = qobject_cast<QQuickItem*>(_itemDelegate->create());
textItem->setParent(this);
textItem->setParentItem(this);
}
QModelIndex ind(_model->index(row, col));
bool active = _model->data(ind, _roleNameToRole["active"]).toBool();
textItem->setProperty("color", active ? "black" : "grey");
textItem->setProperty("text", _model->data(ind));
textItem->setX(_colXPositions[col] + _itemHorizontalPadding);
textItem->setY(-2 + _dataRowsMaxHeight + _itemVerticalPadding + row * _dataRowsMaxHeight);
textItem->setZ(-4);
textItem->setVisible(true);
_cellTextItems[col][row] = textItem;
}
return _cellTextItems[col][row];
}
示例9: initImage
void TelegramImageElement::initImage()
{
if(p->image)
return;
QQmlEngine *engine = qmlEngine(this);
QQmlContext *context = qmlContext(this);
if(!engine || !context)
return;
QQmlComponent component(engine);
QString qmlImageCreationCode = p->qmlImageCreationCode;
if(qmlImageCreationCode.isEmpty())
qmlImageCreationCode = QString("import QtQuick %1\n"
"Image { anchors.fill: parent; }").arg(p->qtQuickVersion);
component.setData(qmlImageCreationCode.toUtf8(), QUrl());
QQuickItem *item = qobject_cast<QQuickItem *>(component.create(context));
if(!item)
return;
item->setParent(this);
item->setParentItem(this);
QHashIterator<QString, QVariant> i(p->properties);
while(i.hasNext())
{
i.next();
item->setProperty(i.key().toUtf8(), i.value());
}
connect(item, SIGNAL(asynchronousChanged()), this, SIGNAL(asynchronousChanged()));
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
connect(item, SIGNAL(autoTransformChanged()), this, SIGNAL(autoTransformChanged()));
#endif
connect(item, SIGNAL(cacheChanged()), this, SIGNAL(cacheChanged()));
connect(item, SIGNAL(fillModeChanged()), this, SIGNAL(fillModeChanged()));
connect(item, SIGNAL(mirrorChanged()), this, SIGNAL(mirrorChanged()));
connect(item, SIGNAL(sourceSizeChanged()), this, SIGNAL(sourceSizeChanged()));
p->image = item;
}
示例10: render
void VCButton::render(QQuickView *view, QQuickItem *parent)
{
if (view == NULL || parent == NULL)
return;
QQmlComponent *component = new QQmlComponent(view->engine(), QUrl("qrc:/VCButtonItem.qml"));
if (component->isError())
{
qDebug() << component->errors();
return;
}
QQuickItem *item = qobject_cast<QQuickItem*>(component->create());
item->setParentItem(parent);
item->setProperty("buttonObj", QVariant::fromValue(this));
}
示例11:
QObject *FlameGraph::appendChild(QObject *parentObject, QQuickItem *parentItem,
QQmlContext *context, const QModelIndex &childIndex,
qreal position, qreal size)
{
QObject *childObject = m_delegate->beginCreate(context);
if (parentItem) {
QQuickItem *childItem = qobject_cast<QQuickItem *>(childObject);
if (childItem)
childItem->setParentItem(parentItem);
}
childObject->setParent(parentObject);
FlameGraphAttached *attached = FlameGraph::qmlAttachedProperties(childObject);
attached->setRelativePosition(position);
attached->setRelativeSize(size);
attached->setModelIndex(childIndex);
m_delegate->completeCreate();
return childObject;
}
示例12: create_packet
void Packet::create_packet(QString name, QObject *main_panel, QQmlApplicationEngine *engine) {
// Load Node QML file
QQmlComponent component(engine, QUrl("qrc:/qml_files/packet.qml"));
// Create QObject
pac_obj = component.create();
// Cast it as a QQuickItem
QQuickItem *item = qobject_cast<QQuickItem*>(pac_obj);
// Set the parent as the main_panel (this changes when added to a link)
item->setParentItem(qobject_cast<QQuickItem*>(main_panel));
item->setProperty("pack_name", name);
#ifdef Q_OS_ANDROID
item->setProperty("packet_size", 50);
offset = 25;
#else
item->setProperty("packet_size", 20);
offset = 13;
#endif
this->name = name;
}
示例13: benchmarkCreation
void tst_StatusIndicator::benchmarkCreation()
{
QFETCH(bool, active);
QQuickWindow window;
window.resize(240, 240);
window.create();
QQmlEngine engine;
// TODO: fix
QString path = QString::fromLatin1(SRCDIR "/LotsOfIndicators%1.qml").arg(active ? "Active" : "Inactive");
QQmlComponent component(&engine, QUrl::fromLocalFile(path));
QVERIFY2(!component.isError(), qPrintable(component.errorString()));
QVERIFY(component.isReady());
QBENCHMARK {
QQuickItem *root = qobject_cast<QQuickItem*>(component.create());
root->setParentItem(window.contentItem());
window.grabWindow();
}
}
示例14: _drawLabel
void Graph::_drawLabel(float x, float y, QString text, QHash<QString, QQuickItem*> &labelCache) {
if(labelComponent == NULL) {
QQmlEngine * engine = new QQmlEngine();
labelComponent = new QQmlComponent(engine, QUrl("qrc:/src/qml/controls/common/_Text.qml", QUrl::StrictMode));
if( labelComponent->status() != QQmlComponent::Ready)
{
qDebug() << ("Error:"+ labelComponent->errorString() );
return; // or maybe throw
}
}
if( labelComponent->status() != QQmlComponent::Ready)
{
return;
}
QQuickItem * label = labelCache[text];
if (!label) { //TODO: Someday, scene graph might have a better text renderer
label= qobject_cast<QQuickItem*>(labelComponent->create());
label->setParentItem(this->parentItem()); //TODO: Who REALLY owns this item? The component? Or the Hash?
label->setProperty("text", text);
label->setProperty("width", "parent.width");
label->children().first()->setProperty("color", m_primaryLineColor.darker());
labelCache[text] = label;
}
if (label != NULL) {
label->setProperty("x", x);
label->setProperty("y", y);
}
}
示例15: attachedProperties
//.........这里部分代码省略.........
QVERIFY(!childAppWindow->property("attached_overlay").value<QQuickItem *>());
QQuickItem *childAppWindowControl = object->property("childAppWindowControl").value<QQuickItem *>();
QVERIFY(childAppWindowControl);
QCOMPARE(childAppWindowControl->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow);
QCOMPARE(childAppWindowControl->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem());
QCOMPARE(childAppWindowControl->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl());
QCOMPARE(childAppWindowControl->property("attached_header").value<QQuickItem *>(), childAppWindow->header());
QCOMPARE(childAppWindowControl->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer());
QCOMPARE(childAppWindowControl->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay());
QQuickItem *childAppWindowItem = object->property("childAppWindowItem").value<QQuickItem *>();
QVERIFY(childAppWindowItem);
QCOMPARE(childAppWindowItem->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow);
QCOMPARE(childAppWindowItem->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem());
QCOMPARE(childAppWindowItem->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl());
QCOMPARE(childAppWindowItem->property("attached_header").value<QQuickItem *>(), childAppWindow->header());
QCOMPARE(childAppWindowItem->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer());
QCOMPARE(childAppWindowItem->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay());
QObject *childAppWindowObject = object->property("childAppWindowObject").value<QObject *>();
QVERIFY(childAppWindowObject);
QVERIFY(!childAppWindowObject->property("attached_window").value<QQuickApplicationWindow *>());
QVERIFY(!childAppWindowObject->property("attached_contentItem").value<QQuickItem *>());
QVERIFY(!childAppWindowObject->property("attached_activeFocusControl").value<QQuickItem *>());
QVERIFY(!childAppWindowObject->property("attached_header").value<QQuickItem *>());
QVERIFY(!childAppWindowObject->property("attached_footer").value<QQuickItem *>());
QVERIFY(!childAppWindowObject->property("attached_overlay").value<QQuickItem *>());
window->show();
window->requestActivate();
QVERIFY(QTest::qWaitForWindowActive(window));
QVERIFY(!childControl->hasActiveFocus());
childControl->forceActiveFocus();
QTRY_VERIFY(childControl->hasActiveFocus());
QCOMPARE(window->activeFocusItem(), childControl);
QCOMPARE(childControl->property("attached_activeFocusControl").value<QQuickItem *>(), childControl);
QQuickItem *header = new QQuickItem;
window->setHeader(header);
QCOMPARE(window->header(), header);
QCOMPARE(childControl->property("attached_header").value<QQuickItem *>(), header);
QQuickItem *footer = new QQuickItem;
window->setFooter(footer);
QCOMPARE(window->footer(), footer);
QCOMPARE(childControl->property("attached_footer").value<QQuickItem *>(), footer);
childAppWindow->show();
childAppWindow->requestActivate();
QVERIFY(QTest::qWaitForWindowActive(childAppWindow));
QVERIFY(!childAppWindowControl->hasActiveFocus());
childAppWindowControl->forceActiveFocus();
QTRY_VERIFY(childAppWindowControl->hasActiveFocus());
QCOMPARE(childAppWindow->activeFocusItem(), childAppWindowControl);
QCOMPARE(childAppWindowControl->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindowControl);
childControl->setParentItem(childAppWindow->contentItem());
QCOMPARE(childControl->window(), childAppWindow);
QCOMPARE(childControl->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow);
QCOMPARE(childControl->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem());
QCOMPARE(childControl->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl());
QCOMPARE(childControl->property("attached_header").value<QQuickItem *>(), childAppWindow->header());
QCOMPARE(childControl->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer());
QCOMPARE(childControl->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay());
childItem->setParentItem(childAppWindow->contentItem());
QCOMPARE(childItem->window(), childAppWindow);
QCOMPARE(childItem->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow);
QCOMPARE(childItem->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem());
QCOMPARE(childItem->property("attached_activeFocusControl").value<QQuickItem *>(), childAppWindow->activeFocusControl());
QCOMPARE(childItem->property("attached_header").value<QQuickItem *>(), childAppWindow->header());
QCOMPARE(childItem->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer());
QCOMPARE(childItem->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay());
childControl->setParentItem(Q_NULLPTR);
QVERIFY(!childControl->window());
QVERIFY(!childControl->property("attached_window").value<QQuickApplicationWindow *>());
QVERIFY(!childControl->property("attached_contentItem").value<QQuickItem *>());
QVERIFY(!childControl->property("attached_activeFocusControl").value<QQuickItem *>());
QVERIFY(!childControl->property("attached_header").value<QQuickItem *>());
QVERIFY(!childControl->property("attached_footer").value<QQuickItem *>());
QVERIFY(!childControl->property("attached_overlay").value<QQuickItem *>());
childItem->setParentItem(Q_NULLPTR);
QVERIFY(!childItem->window());
QVERIFY(!childItem->property("attached_window").value<QQuickApplicationWindow *>());
QVERIFY(!childItem->property("attached_contentItem").value<QQuickItem *>());
QVERIFY(!childItem->property("attached_activeFocusControl").value<QQuickItem *>());
QVERIFY(!childItem->property("attached_header").value<QQuickItem *>());
QVERIFY(!childItem->property("attached_footer").value<QQuickItem *>());
QVERIFY(!childItem->property("attached_overlay").value<QQuickItem *>());
// ### A temporary workaround to unblock the CI until the crash caused
// by https://codereview.qt-project.org/#/c/108517/ has been fixed...
window->hide();
qApp->processEvents();
}