Qml ComboBox with TextField in Popup











up vote
2
down vote

favorite












I have created a custom ComboBox that uses a ListView with a TextField in the footer, that's used to dynamically add options to the ComboBox.
The problem is, that as soon as the popup loses focus (so when the TextField receives focus), the popup gets closed.
I tried to force the popup to stay open, which does work, but then prevents the TextField from receiving focus (I guess because the popup regains focus as soon as open() is called).



ComboBox {
// ...
popup: Popup {
property bool forceOpen: false
onClosed: {
if(forceOpen)
open()
}

contentItem: ListView {
// ...
footer: TextField {
onPressed: forceOpen = true
}
}
}
}


I also tried all values for the closePolicy property of the Popup, but none of them helped.



I am using Qt5.11. The forceOpen solution used to work with Qt 5.10, but does not anymore.










share|improve this question




















  • 1




    This might be a bit of a weird question but why not to use ComboBox instead of creating the custom one?
    – folibis
    Nov 6 at 10:10










  • Of, ofcourse I am using a regular ComboBox, I edited the entry post.
    – Johannes Stricker
    Nov 6 at 12:28















up vote
2
down vote

favorite












I have created a custom ComboBox that uses a ListView with a TextField in the footer, that's used to dynamically add options to the ComboBox.
The problem is, that as soon as the popup loses focus (so when the TextField receives focus), the popup gets closed.
I tried to force the popup to stay open, which does work, but then prevents the TextField from receiving focus (I guess because the popup regains focus as soon as open() is called).



ComboBox {
// ...
popup: Popup {
property bool forceOpen: false
onClosed: {
if(forceOpen)
open()
}

contentItem: ListView {
// ...
footer: TextField {
onPressed: forceOpen = true
}
}
}
}


I also tried all values for the closePolicy property of the Popup, but none of them helped.



I am using Qt5.11. The forceOpen solution used to work with Qt 5.10, but does not anymore.










share|improve this question




















  • 1




    This might be a bit of a weird question but why not to use ComboBox instead of creating the custom one?
    – folibis
    Nov 6 at 10:10










  • Of, ofcourse I am using a regular ComboBox, I edited the entry post.
    – Johannes Stricker
    Nov 6 at 12:28













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have created a custom ComboBox that uses a ListView with a TextField in the footer, that's used to dynamically add options to the ComboBox.
The problem is, that as soon as the popup loses focus (so when the TextField receives focus), the popup gets closed.
I tried to force the popup to stay open, which does work, but then prevents the TextField from receiving focus (I guess because the popup regains focus as soon as open() is called).



ComboBox {
// ...
popup: Popup {
property bool forceOpen: false
onClosed: {
if(forceOpen)
open()
}

contentItem: ListView {
// ...
footer: TextField {
onPressed: forceOpen = true
}
}
}
}


I also tried all values for the closePolicy property of the Popup, but none of them helped.



I am using Qt5.11. The forceOpen solution used to work with Qt 5.10, but does not anymore.










share|improve this question















I have created a custom ComboBox that uses a ListView with a TextField in the footer, that's used to dynamically add options to the ComboBox.
The problem is, that as soon as the popup loses focus (so when the TextField receives focus), the popup gets closed.
I tried to force the popup to stay open, which does work, but then prevents the TextField from receiving focus (I guess because the popup regains focus as soon as open() is called).



ComboBox {
// ...
popup: Popup {
property bool forceOpen: false
onClosed: {
if(forceOpen)
open()
}

contentItem: ListView {
// ...
footer: TextField {
onPressed: forceOpen = true
}
}
}
}


I also tried all values for the closePolicy property of the Popup, but none of them helped.



I am using Qt5.11. The forceOpen solution used to work with Qt 5.10, but does not anymore.







qt combobox popup qml qcombobox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 6 at 12:28

























asked Nov 5 at 17:46









Johannes Stricker

12119




12119








  • 1




    This might be a bit of a weird question but why not to use ComboBox instead of creating the custom one?
    – folibis
    Nov 6 at 10:10










  • Of, ofcourse I am using a regular ComboBox, I edited the entry post.
    – Johannes Stricker
    Nov 6 at 12:28














  • 1




    This might be a bit of a weird question but why not to use ComboBox instead of creating the custom one?
    – folibis
    Nov 6 at 10:10










  • Of, ofcourse I am using a regular ComboBox, I edited the entry post.
    – Johannes Stricker
    Nov 6 at 12:28








1




1




This might be a bit of a weird question but why not to use ComboBox instead of creating the custom one?
– folibis
Nov 6 at 10:10




This might be a bit of a weird question but why not to use ComboBox instead of creating the custom one?
– folibis
Nov 6 at 10:10












Of, ofcourse I am using a regular ComboBox, I edited the entry post.
– Johannes Stricker
Nov 6 at 12:28




Of, ofcourse I am using a regular ComboBox, I edited the entry post.
– Johannes Stricker
Nov 6 at 12:28












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Your problem should be fixed if you do not accept the focus on the ComboBox:



ComboBox {
focusPolicy: Qt.NoFocus
popup: Popup {
// ...
}
}





share|improve this answer





















  • Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
    – Johannes Stricker
    Nov 7 at 6:42











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159560%2fqml-combobox-with-textfield-in-popup%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Your problem should be fixed if you do not accept the focus on the ComboBox:



ComboBox {
focusPolicy: Qt.NoFocus
popup: Popup {
// ...
}
}





share|improve this answer





















  • Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
    – Johannes Stricker
    Nov 7 at 6:42















up vote
1
down vote



accepted










Your problem should be fixed if you do not accept the focus on the ComboBox:



ComboBox {
focusPolicy: Qt.NoFocus
popup: Popup {
// ...
}
}





share|improve this answer





















  • Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
    – Johannes Stricker
    Nov 7 at 6:42













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Your problem should be fixed if you do not accept the focus on the ComboBox:



ComboBox {
focusPolicy: Qt.NoFocus
popup: Popup {
// ...
}
}





share|improve this answer












Your problem should be fixed if you do not accept the focus on the ComboBox:



ComboBox {
focusPolicy: Qt.NoFocus
popup: Popup {
// ...
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 6 at 14:08









augre

671312




671312












  • Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
    – Johannes Stricker
    Nov 7 at 6:42


















  • Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
    – Johannes Stricker
    Nov 7 at 6:42
















Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
– Johannes Stricker
Nov 7 at 6:42




Awesome, that really solved the problem. And it doesn't even require the messy workaround with a forceOpen property. Thanks!
– Johannes Stricker
Nov 7 at 6:42


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159560%2fqml-combobox-with-textfield-in-popup%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings