Menu: cull non-visible items when `contentItem` inherits Item
For a custom menu control, when the contentItem does not inherit from ItemView, the text overlaps. A related bug is QTBUG-53262, but this problem is only fixed for the ItemView control. Since the contentItem control can accept the Item control, I think the repair only for ItemView has limitations. Therefore, this submission cancels the restriction on the type of contentitem. Pick-to: 6.3 6.4 Fixes: QTBUG-104470 Change-Id: I7e697e3cb993475d157a92f37d9512e4a9872387 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
parent
9d22088d93
commit
6173fc0e4b
|
@ -204,8 +204,7 @@ void QQuickMenuPrivate::insertItem(int index, QQuickItem *item)
|
|||
{
|
||||
contentData.append(item);
|
||||
item->setParentItem(contentItem);
|
||||
if (qobject_cast<QQuickItemView *>(contentItem))
|
||||
QQuickItemPrivate::get(item)->setCulled(true); // QTBUG-53262
|
||||
QQuickItemPrivate::get(item)->setCulled(true); // QTBUG-53262
|
||||
if (complete)
|
||||
resizeItem(item);
|
||||
QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent);
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
ApplicationWindow {
|
||||
width: 200
|
||||
height: 200
|
||||
property alias menu: menu
|
||||
|
||||
Menu {
|
||||
id: menu
|
||||
|
||||
contentItem: FocusScope {
|
||||
implicitHeight: view.implicitHeight
|
||||
Button {
|
||||
anchors {
|
||||
top: parent.top
|
||||
topMargin: 5
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
z: 1
|
||||
text: "Button Up"
|
||||
visible: view.interactive
|
||||
}
|
||||
ListView {
|
||||
id: view
|
||||
width: parent.width
|
||||
implicitHeight: Math.min(contentHeight, 300)
|
||||
model: menu.contentModel
|
||||
|
||||
clip: true
|
||||
currentIndex: menu.currentIndex
|
||||
ScrollIndicator.vertical: ScrollIndicator {}
|
||||
}
|
||||
Button {
|
||||
anchors {
|
||||
bottom: parent.bottom
|
||||
bottomMargin: 5
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
z: 1
|
||||
text: "Button Down"
|
||||
visible: view.interactive
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: 20
|
||||
MenuItem {
|
||||
objectName: "Item: " + modelData
|
||||
text: objectName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -78,6 +78,7 @@ private slots:
|
|||
void menuItemWidthAfterImplicitWidthChanged();
|
||||
void menuItemWidthAfterRetranslate();
|
||||
void giveMenuItemFocusOnButtonPress();
|
||||
void customMenuCullItems();
|
||||
};
|
||||
|
||||
tst_QQuickMenu::tst_QQuickMenu()
|
||||
|
@ -1977,6 +1978,27 @@ void tst_QQuickMenu::giveMenuItemFocusOnButtonPress()
|
|||
QTRY_VERIFY(menu->isOpened());
|
||||
}
|
||||
|
||||
void tst_QQuickMenu::customMenuCullItems()
|
||||
{
|
||||
QQuickControlsApplicationHelper helper(this, QLatin1String("customMenuCullItems.qml"));
|
||||
QVERIFY2(helper.ready, helper.failureMessage());
|
||||
QQuickApplicationWindow *window = helper.appWindow;
|
||||
window->show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(window));
|
||||
|
||||
QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
|
||||
QVERIFY(menu);
|
||||
menu->open();
|
||||
QTRY_VERIFY(menu->isOpened());
|
||||
|
||||
QQuickItem *menuItemFirst = menu->itemAt(0);
|
||||
QQuickItem *menuItemLast = menu->itemAt(menu->count() - 1);
|
||||
QVERIFY(menuItemFirst);
|
||||
QVERIFY(menuItemLast);
|
||||
QTRY_VERIFY(!QQuickItemPrivate::get(menuItemFirst)->culled);
|
||||
QTRY_VERIFY(QQuickItemPrivate::get(menuItemLast)->culled);
|
||||
}
|
||||
|
||||
QTEST_QUICKCONTROLS_MAIN(tst_QQuickMenu)
|
||||
|
||||
#include "tst_qquickmenu.moc"
|
||||
|
|
Loading…
Reference in New Issue