本文整理汇总了C++中QQuickItem::setX方法的典型用法代码示例。如果您正苦于以下问题:C++ QQuickItem::setX方法的具体用法?C++ QQuickItem::setX怎么用?C++ QQuickItem::setX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQuickItem
的用法示例。
在下文中一共展示了QQuickItem::setX方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updatePositionMarker
void Tracking::updatePositionMarker()
{
if ( m_marbleQuickItem && m_positionMarker && m_positionMarkerType == Circle ) {
Coordinate* position = 0;
bool visible = (m_marbleQuickItem->model()->planetId() == QLatin1String("earth"));
if ( m_positionSource && m_positionSource->hasPosition() ) {
position = m_positionSource->position();
} else if ( hasLastKnownPosition() ) {
position = lastKnownPosition();
} else {
visible = false;
}
qreal x(0), y(0);
if ( position ) {
Marble::GeoDataCoordinates const pos( position->longitude(), position->latitude(), 0.0, GeoDataCoordinates::Degree );
visible = visible && m_marbleQuickItem->map()->viewport()->screenCoordinates( pos.longitude(), pos.latitude(), x, y );
QQuickItem* item = qobject_cast<QQuickItem*>( m_positionMarker );
if ( item ) {
item->setVisible( visible );
if ( visible ) {
item->setX( x - item->width() / 2.0 );
item->setY( y - item->height() / 2.0 );
}
}
}
} else if ( m_positionMarkerType != Circle ) {
QQuickItem* item = qobject_cast<QQuickItem*>( m_positionMarker );
if ( item ) {
item->setVisible( false );
}
}
}
示例2: QQmlComponent
QQuickItem * DataSetView::createRowNumber(int row)
{
//std::cout << "createRowNumber("<<row<<") called!\n" << std::flush;
if(_rowNumberDelegate == NULL)
{
_rowNumberDelegate = new QQmlComponent(qmlEngine(this));
_rowNumberDelegate->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 * rowNumber = NULL;
if(_rowNumberItems.count(row) == 0 || _rowNumberItems[row] == NULL)
{
if(_rowNumberStorage.size() > 0)
{
#ifdef DEBUG_VIEWPORT
std::cout << "createRowNumber("<<row<<") from storage!\n" << std::flush;
#endif
rowNumber = _rowNumberStorage.top();
_rowNumberStorage.pop();
}
else
{
#ifdef DEBUG_VIEWPORT
std::cout << "createRowNumber("<<row<<") ex nihilo!\n" << std::flush;
#endif
rowNumber = qobject_cast<QQuickItem*>(_rowNumberDelegate->create());
rowNumber->setParent(this);
rowNumber->setParentItem(this);
}
rowNumber->setProperty("z", 10);
rowNumber->setProperty("text", QString::fromStdString(std::to_string(row + 1))); //Nobody wants zero-based rows...
rowNumber->setY(_dataRowsMaxHeight * (1 + row));
rowNumber->setZ(-3);
rowNumber->setHeight(_dataRowsMaxHeight);
rowNumber->setWidth(_rowNumberMaxWidth);
rowNumber->setVisible(true);
_rowNumberItems[row] = rowNumber;
}
else
rowNumber = _rowNumberItems[row];
rowNumber->setX(_viewportX);
return _rowNumberItems[row];
}
示例3: addItem
void CustomUndoStack::addItem(QQuickItem *itemParent, QQmlComponent *itemComponent)
{
if (!itemParent || !itemComponent)
return;
QQuickItem *item = qobject_cast<QQuickItem*>(itemComponent->create());
if (!item) {
qWarning() << "Failed to create item";
return;
}
item->setX(mItemsAdded * 25);
item->setY(mItemsAdded * 25);
push(new AddCommand(itemParent, item));
++mItemsAdded;
}
示例4: 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];
}
示例5: layoutChildrenWithDefaultSize
void StretchRow::layoutChildrenWithDefaultSize() {
//static int count = 0;
//qDebug() << "Row Default Size" << ++count;
Q_ASSERT(m_defaultSize != 0);
const QList<QQuickItem *> childrenList = childItems();
if (childrenList.isEmpty()) return;
const int layoutHeight = height();
qreal currX = m_leftMargin;
for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) {
QQuickItem* child = (*it);
if (child == Q_NULLPTR || !child->isVisible()) {
continue;
}
// add spacing if it is not the first item:
if (currX > 0) {
currX += m_spacing;
}
if (currX != child->x()) child->setX(currX);
// check if item has a stretch proportion set:
if (child->implicitWidth() < 0) {
// yes -> set it to default size:
qreal newWidth = m_defaultSize * child->implicitWidth() * -1;
if (newWidth != child->width()) child->setWidth(newWidth);
}
// set height of all items to fill the layout:
if (layoutHeight != child->height()) child->setHeight(layoutHeight);
currX += child->width();
}
currX += m_rightMargin;
// set implicit size to fit all items:
if (currX != implicitWidth()) setImplicitWidth(currX);
}
示例6: layoutChildrenWithProportions
void StretchRow::layoutChildrenWithProportions() {
//static int count = 0;
//qDebug() << "Row Proportions" << ++count;
const QList<QQuickItem*> childrenList = childItems();
if (childrenList.isEmpty()) return;
if (width() <= 0) return;
int visibleItems = 0;
qreal availableForStretch = width() - m_leftMargin - m_rightMargin;
qreal sumStretchProportions = 0.0;
// iterate over all children and calculate available size to stretch items:
for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) {
QQuickItem* child = (*it);
if (child == Q_NULLPTR || !child->isVisible()) {
continue;
}
if (child->implicitWidth() >= 0) {
// no stretch proportion set -> leave size and remove it from available space:
availableForStretch -= child->width();
} else {
// a stretch proportion is set -> add it to sum:
sumStretchProportions += (child->implicitWidth() * -1);
}
visibleItems++;
}
// remove spacing from available space:
availableForStretch -= m_spacing * (visibleItems - 1);
const int layoutHeight = height();
QPointer<QQuickItem> lastStretchItem = nullptr;
qreal currX = m_leftMargin;
for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) {
QQuickItem* child = (*it);
if (child == Q_NULLPTR || !child->isVisible()) {
continue;
}
// add spacing if it is not the first item:
if (currX > 0) {
currX += m_spacing;
}
if (currX != child->x()) child->setX(currX);
// check if item has a stretch proportion set (if not do nothing):
if (child->implicitWidth() < 0) {
// get the stretch proportion:
qreal stretchProportion = (child->implicitWidth() * -1);
// calculate the relation of the total space available for stretched items
// that this item will use:
// (sumStretchProportion can not be 0 (in divison) because if this "if" is executed,
// there has been at least one item with a stretch proportion set)
qreal relationOfSpaceAvailableForStretch = stretchProportion / sumStretchProportions;
qreal newWidth = qRound(availableForStretch * relationOfSpaceAvailableForStretch);
if (newWidth != child->width()) child->setWidth(newWidth);
lastStretchItem = child;
}
// set height of all items to fill the layout:
if (layoutHeight != child->height()) child->setHeight(layoutHeight);
currX += child->width();
}
currX += m_rightMargin;
// check if last item fills whole remaining space in this layout:
// (can happen because of rounding mistakes)
if (lastStretchItem) {
double pxMissing = width() - currX;
if (pxMissing > 0.0001) {
// qInfo() << "StretchRow layout mismatch: " << pxMissing;
// it does not -> adjust it:
lastStretchItem->setWidth(lastStretchItem->width() + pxMissing);
}
}
}
示例7: reconfigureLayout
void QQuickComponentsLinearLayout::reconfigureLayout()
{
if (!isComponentComplete())
return;
const int count = m_items.count();
if (count == 0)
return;
qreal totalSpacing = 0;
qreal totalSizeHint = 0;
qreal totalMinimumSize = 0;
qreal totalMaximumSize = 0;
QVector<QQuickComponentsLayoutInfo> itemData;
for (int i = 0; i < count; i++) {
QQuickItem *item = m_items.at(i);
QObject *attached = qmlAttachedPropertiesObject<QQuickComponentsLayout>(item);
QQuickComponentsLayoutAttached *info = static_cast<QQuickComponentsLayoutAttached *>(attached);
QQuickComponentsLayoutInfo data;
if (m_orientation == Horizontal) {
data.sizeHint = item->implicitWidth();
data.minimumSize = info->minimumWidth();
data.maximumSize = info->maximumWidth();
data.expansive = (info->horizontalSizePolicy() == QQuickComponentsLayout::Expanding);
data.stretch = info->horizontalSizePolicy() == Expanding ? 1.0 : 0;
} else {
data.sizeHint = item->implicitHeight();
data.minimumSize = info->minimumHeight();
data.maximumSize = info->maximumHeight();
data.expansive = (info->verticalSizePolicy() == QQuickComponentsLayout::Expanding);
data.stretch = info->verticalSizePolicy() == Expanding ? 1.0 : 0;
}
itemData.append(data);
// sum
totalSizeHint += data.sizeHint;
totalMinimumSize += data.minimumSize;
totalMaximumSize += data.maximumSize;
// don't count last spacing
if (i < count - 1)
totalSpacing += data.spacing + m_spacing;
}
if (m_orientation == Horizontal) {
qDeclarativeLayoutCalculate(itemData, 0, count, 0, width(), m_spacing);
for (int i = 0; i < count; i++) {
QQuickItem *item = m_items.at(i);
const QQuickComponentsLayoutInfo &data = itemData.at(i);
item->setX(data.pos);
item->setY(height()/2 - item->height()/2);
item->setWidth(data.size);
}
} else {
qDeclarativeLayoutCalculate(itemData, 0, count, 0, height(), m_spacing);
for (int i = 0; i < count; i++) {
QQuickItem *item = m_items.at(i);
const QQuickComponentsLayoutInfo &data = itemData.at(i);
item->setY(data.pos);
item->setX(width()/2 - item->width()/2);
item->setHeight(data.size);
}
}
// propagate hints to upper levels
QObject *attached = qmlAttachedPropertiesObject<QQuickComponentsLayout>(this);
QQuickComponentsLayoutAttached *info = static_cast<QQuickComponentsLayoutAttached *>(attached);
if (m_orientation == Horizontal) {
setImplicitWidth(totalSizeHint);
info->setMinimumWidth(totalMinimumSize + totalSpacing);
info->setMaximumWidth(totalMaximumSize + totalSpacing);
} else {
setImplicitHeight(totalSizeHint);
info->setMinimumHeight(totalMinimumSize + totalSpacing);
info->setMaximumHeight(totalMaximumSize + totalSpacing);
}
}