📄 qgraphicsitem.cpp
字号:
q_ptr->update(); // Update children with explicitly = false. foreach (QGraphicsItem *child, children) { if (!newVisible || !child->d_ptr->explicitlyHidden) child->d_ptr->setVisibleHelper(newVisible, false); }}/*! If \a visible is true, the item is made visible. Otherwise, the item is made invisible. Invisible items are not painted, nor do they receive any events. In particular, mouse events pass right through invisible items, and are delivered to any item that may be behind. Invisible items are also unselectable, they cannot take input focus, and are not detected by QGraphicsScene's item location functions. If an item becomes invisible while grabbing the mouse, (i.e., while it is receiving mouse events,) it will automatically lose the mouse grab, and the grab is not regained by making the item visible again; it must receive a new mouse press to regain the mouse grab. Similarly, an invisible item cannot have focus, so if the item has focus when it becomes invisible, it will lose focus, and the focus is not regained by simply making the item visible again. If you hide a parent item, all its children will also be hidden. If you show a parent item, all children will be shown, unless they have been explicitly hidden (i.e., if you call setVisible(false) on a child, it will not be reshown even if its parent is hidden, and then shown again). Items are visible by default; it is unnecessary to call setVisible() on a new item. \sa isVisible(), show(), hide()*/void QGraphicsItem::setVisible(bool visible){ d_ptr->setVisibleHelper(visible, /* explicit = */ true);}/*! \fn void QGraphicsItem::hide() Hides the item. (Items are visible by default.) This convenience function is equivalent to calling \c setVisible(false). \sa show(), setVisible()*//*! \fn void QGraphicsItem::show() Shows the item. (Items are visible by default.) This convenience function is equivalent to calling \c setVisible(true). \sa hide(), setVisible()*//*! Returns true if the item is enabled; otherwise, false is returned. \sa setEnabled()*/bool QGraphicsItem::isEnabled() const{ return d_ptr->enabled;}/*! \internal Sets this item's visibility to \a newEnabled. If \a explicitly is true, this item will be "explicitly" \a newEnabled; otherwise, it.. will not be.*/void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bool update){ // Update explicit bit. if (explicitly) explicitlyDisabled = newEnabled ? 0 : 1; // Check if there's nothing to do. if (enabled == quint32(newEnabled)) return; // Certain properties are dropped when an item is disabled. if (!newEnabled) { if (scene && scene->mouseGrabberItem() == q_ptr) scene->d_func()->mouseGrabberItem = 0; if (q_ptr->hasFocus()) q_ptr->clearFocus(); if (q_ptr->isSelected()) q_ptr->setSelected(false); } // Modify the property. enabled = q_ptr->itemChange(QGraphicsItem::ItemEnabledChange, quint32(newEnabled)).toBool(); // Schedule redraw. if (update) q_ptr->update(); foreach (QGraphicsItem *child, children) { if (!newEnabled || !child->d_ptr->explicitlyDisabled) child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false); }}/*! If \a enabled is true, the item is enabled; otherwise, it is disabled. Disabled items are visible, but they do not receive any events, and cannot take focus nor be selected. Mouse events are discarded; they are not propagated unless the item is also invisible, or if it does not accept mouse events (see acceptedMouseButtons()). A disabled item cannot become the mouse grabber, and as a result of this, an item loses the grab if it becomes disabled when grabbing the mouse, just like it loses focus if it had focus when it was disabled. Disabled items are traditionally drawn using grayed-out colors (see \l QPalette::Disabled). If you disable a parent item, all its children will also be disabled. If you enable a parent item, all children will be enabled, unless they have been explicitly disabled (i.e., if you call setEnabled(false) on a child, it will not be reenabled if its parent is disabled, and then enabled again). Items are enabled by default. \sa isEnabled()*/void QGraphicsItem::setEnabled(bool enabled){ d_ptr->setEnabledHelper(enabled, /* explicitly = */ true);}/*! Returns true if this item is selected; otherwise, false is returned. Items that are in a group inherit the group's selected state. Items are not selected by default. \sa setSelected(), QGraphicsScene::setSelectionArea()*/bool QGraphicsItem::isSelected() const{ if (QGraphicsItemGroup *group = this->group()) return group->isSelected(); return d_ptr->selected;}/*! If \a selected is true and this item is selectable, this item is selected; otherwise, it is unselected. If the item is in a group, the whole group's selected state is toggled by this function. If the group is selected, all items in the group are also selected, and if the group is not selected, no item in the group is selected. Only visible, enabled, selectable items can be selected. If \a selected is true and this item is either invisible or disabled or unselectable, this function does nothing. By default, items cannot be selected. To enable selection, set the ItemIsSelectable flag. This function is provided for convenience, allowing individual toggling of the selected state of an item. However, a more common way of selecting items is to call QGraphicsScene::setSelectionArea(), which will call this function for all visible, enabled, and selectable items within a specified area on the scene. \sa isSelected(), QGraphicsScene::selectedItems()*/void QGraphicsItem::setSelected(bool selected){ if (QGraphicsItemGroup *group = this->group()) { group->setSelected(selected); return; } if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible) selected = false; if (d_ptr->selected == selected) return; d_ptr->selected = itemChange(ItemSelectedChange, quint32(selected)).toBool(); update(); if (d_ptr->scene) { QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func(); if (selected) { sceneD->selectedItems << this; } else { // QGraphicsScene::selectedItems() lazily pulls out all items that are // no longer selected. } if (!sceneD->selectionChanging) emit d_ptr->scene->selectionChanged(); }}/*! Returns true if this item can accept drag and drop events; otherwise, returns false. By default, items do not accept drag and drop events; items are transparent to drag and drop. \sa setAcceptDrops()*/bool QGraphicsItem::acceptDrops() const{ return d_ptr->acceptDrops;}/*! If \a on is true, this item will accept drag and drop events; otherwise, it is transparent for drag and drop events. By default, items do not accept drag and drop events. \sa acceptDrops()*/void QGraphicsItem::setAcceptDrops(bool on){ d_ptr->acceptDrops = on;}/*! Returns the mouse buttons that this item accepts mouse events for. By default, all mouse buttons are accepted. If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that mouse button. However, if the item does not accept the button, QGraphicsScene will forward the mouse events to the first item beneath it that does. \sa setAcceptedMouseButtons(), mousePressEvent()*/Qt::MouseButtons QGraphicsItem::acceptedMouseButtons() const{ return Qt::MouseButtons(d_ptr->acceptedMouseButtons);}/*! Sets the mouse \a buttons that this item accepts mouse events for. By default, all mouse buttons are accepted. If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that button. However, if the item does not accept the mouse button, QGraphicsScene will forward the mouse events to the first item beneath it that does. To disable mouse events for an item (i.e., make it transparent for mouse events), call setAcceptedMouseButtons(0). \sa acceptedMouseButtons(), mousePressEvent()*/void QGraphicsItem::setAcceptedMouseButtons(Qt::MouseButtons buttons){ if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) { if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() == this) d_ptr->scene->d_func()->mouseGrabberItem = 0; d_ptr->acceptedMouseButtons = quint32(buttons); }}/*! Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false. By default, items do not accept hover events. \sa setAcceptedMouseButtons()*/bool QGraphicsItem::acceptsHoverEvents() const{ return d_ptr->acceptsHover;}/*! If \a enabled is true, this item will accept hover events; otherwise, it will ignore them. By default, items do not accept hover events. Hover events are delivered when there is no current mouse grabber item. They are sent when the mouse cursor enters an item, when it moves around inside the item, and when the cursor leaves an item. Hover events are commonly used to highlight an item when it's entered, and for tracking the mouse cursor as it hovers over the item (equivalent to QWidget::mouseTracking). Parent items receive hover enter events before their children, and leave events after their children. The parent does not receive a hover leave event if the cursor enters a child, though; the parent stays "hovered" until the cursor leaves its area, including its children's areas. If a parent item handles child events (setHandlesChildEvents()), it will receive hover move, drag move, and drop events as the cursor passes through its children, but it does not receive hover enter and hover leave, nor drag enter and drag leave events on behalf of its children. \sa acceptsHoverEvents(), hoverEnterEvent(), hoverMoveEvent(), hoverLeaveEvent()*/void QGraphicsItem::setAcceptsHoverEvents(bool enabled){ d_ptr->acceptsHover = quint32(enabled);}/*! Returns true if this item handles child events (i.e., all events intended for any of its children are instead sent to this item); otherwise, false is returned. This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually. The default is to return false; children handle their own events. The exception for this is if the item is a QGraphicsItemGroup, then it defaults to return true. \sa setHandlesChildEvents()*/bool QGraphicsItem::handlesChildEvents() const{ return d_ptr->handlesChildEvents;}/*! If \a enabled is true, this item is set to handle all events for all its children (i.e., all events intented for any of its children are instead sent to this item); otherwise, if \a enabled is false, this item will only handle its own events. The default value is false. This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually. If a child item accepts hover events, its parent will receive hover move events as the cursor passes through the child, but it does not receive hover enter and hover leave events on behalf of its child. \sa handlesChildEvents()*/void QGraphicsItem::setHandlesChildEvents(bool enabled){ if (d_ptr->handlesChildEvents == enabled) return; d_ptr->handlesChildEvents = enabled; d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));}/*! Returns true if this item has focus (i.e., can accept key events); otherwise, returns false. \sa setFocus(), QGraphicsScene::setFocusItem()*/bool QGraphicsItem::hasFocus() const{ return d_ptr->scene && d_ptr->scene->focusItem() == this;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -