
Проблема с QML Popup
Здравствуйте! Делаю портативный прибор для инженерных измерений, задача - обеспечить как сенсорное управления с экрана, так и управление интерфейсом физическими кнопками. Все шло хорошо, пока не задействовал Popup. Необходимо открыть Popup-меню, щелкнуть нужную кнопку, которая закроет это Popup-меню и вызовет другое Popup-окно. Проблема в следующем: если тыкать пальцем по кнопке Popup-меню на экране, то второй Popup открывается и все отлично, но если действовать физическими кнопками, то второй Popup открывается только при условии отсутствия метода его закрытия. Вот код:
Item { Connections { target: but_thread onSendToQml: { but_name = button_name ... //обработка нажатий физических клавиш в случае открытого Popup-меню if(contextMenu.opened === true){ if(but_name=="cancel"){ contextMenu.close() } if(but_name=="ok"){ if(contextMenu.index===0) but_create.clicked() if(contextMenu.index===1) but_edit.clicked() if(contextMenu.index===2) but_del.clicked() } if(but_name=="down"){ if(contextMenu.index>-1 && contextMenu.index<3) contextMenu.index++ if(contextMenu.index==3) contextMenu.index=0 } if(but_name=="up"){ if(contextMenu.index>-1 && contextMenu.index<3) contextMenu.index = contextMenu.index - 1 if(contextMenu.index==-1) contextMenu.index=2 } } //обработка нажатий физических клавиш в случае открытого второго Popup-окна if(pop_create_database.opened === true){ if(but_name=="cancel"){ pop_create_database.close() } if(but_name=="ok"){ if(pop_create_database.index===0) but_create_database.clicked() //если здесь добавить pop_create_database.close(), то pop_create_database не откроется через but_create.clicked() if(pop_create_database.index===1) but_cancel.clicked() } if(but_name=="down"){ if(pop_create_database.index>-1 && pop_create_database.index<2) pop_create_database.index++ if(pop_create_database.index==2) pop_create_database.index=0 } if(but_name=="up"){ if(pop_create_database.index>-1 && pop_create_database.index<2) pop_create_database.index = pop_create_database.index - 1 if(pop_create_database.index==-1) pop_create_database.index=1 } } } } Popup { id: contextMenu x: win.width/2 - width/2 y: 200 width: but_edit.width + 20 height: but_create.height + but_edit.height + but_del.height + 40 property int index: 0 Column { anchors.centerIn: parent spacing: 10 Button { id: but_create anchors.left: contextMenu.left width: but_edit.width text: "Создать базу данных" highlighted: contextMenu.index === 0 ? true : false onClicked: { contextMenu.close() pop_create_database.open() contextMenu.index = 0 } } Button { id: but_edit text: "Редактировать название базы" highlighted: contextMenu.index === 1 ? true : false onClicked: { contextMenu.index = 1 } } Button { id: but_del width: but_edit.width text: "Удалить базу" highlighted: contextMenu.index === 2 ? true : false onClicked: { contextMenu.index = 2 } } } } Popup { id: pop_create_database property int index: 0 x: win.width/2 - width/2 y: 120 z: 10 width: 300 height: tf_create_database.height + but_create_database.height + but_cancel.height + 40 focus: true closePolicy: Popup.NoAutoClose Column { anchors.centerIn: parent spacing: 10 focus: true TextField { id: tf_create_database objectName: "tf_create_database" width: pop_create_database.width - 20 placeholderText: "Введите название базы" focus: true Component.onCompleted: { tf_create_database.focus = true } } Button { id: but_create_database anchors.horizontalCenter: tf_create_database.horizontalCenter width: 200 highlighted: pop_create_database.index === 0 ? true : false text: "Создать" onClicked: { qmlSignal_create_db() db_list.updateModel() pop_create_database.close() //вот если эту строку удалить, то все работает хорошо, но как тогда этот Popup закрыть? } } Button { id: but_cancel anchors.horizontalCenter: tf_create_database.horizontalCenter width: 200 highlighted: pop_create_database.index === 1 ? true : false text: "Отмена" onClicked: { pop_create_database.close() } } } } }
Подскажите, как решить или обойти эту проблему?

We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
- Unknown akadamn
- Jan. 24, 2025, 5:14 p.m.
Qt - Test 001. Signals and slots
- Result:84points,
- Rating points4
- Unknown akadamn
- Jan. 24, 2025, 4:22 p.m.
Qt - Test 001. Signals and slots
- Result:42points,
- Rating points-8


Добавлю, вызов console.log(pop_create_database.opened) дает true... Popup открыт, но его не видно :(
Ух, извиняюсь. Увидел что при вызове второго Popup происходит запрос в базу по его кнопке. То есть Popup не успев прорисоваться получает клик по своей кнопке создания базы, вызывающей метод его закрытия. Поменял индексы и все заработало. Похоже что вместо одного нажатия физической кнопки ОК происходит несколько, хоть и ставил задержку 200 мс. Извиняюсь еще раз.