How to open new window after doubleclick so that it becomes active?










0















I'm trying to do a seemingly simple thing: after a double-click in one window, I want to open a second top-level (non-modal) window and activate it. However, whatever I do the second window doesn't get activated, the focus remains in the first window.



Here's a minimal example:



import QtQuick 2.11
import QtQuick.Controls 2.4

ApplicationWindow
id: root
height: 480
width: 640
visible: true

MouseArea
anchors.fill: parent
onDoubleClicked:
var w = otherWindowComponent.createObject(root)
w.show()
w.requestActivate() // same effect when removed



Component
id: otherWindowComponent
ApplicationWindow
id: child
width: 400
height: 300

Rectangle
color: "blue"
width: 100
height: 100
focus: true






Am I missing something? Thanks!



UPD: A bit of extra information:



  1. I'm on Windows 10 64-bit

  2. When I replace onDoubleClicked with onClicked, the window gets activated as expected.









share|improve this question
























  • Have your tried calling forceActiveFocus on the create window/item? You can do so in Component.onCompleted

    – Felix
    Nov 16 '18 at 13:17











  • I can't call forceActiveFocus on a Window because it requires an Item. Calling it on the embedded blue Rect doesn't help.

    – Alex Jenter
    Nov 16 '18 at 13:33












  • You can try to call requestActivate() in Component.onCompleted

    – xeco
    Nov 16 '18 at 19:44











  • @AlexJenter How to verify that the focus has not changed?

    – eyllanesc
    Nov 17 '18 at 3:56






  • 1





    @AlexJenter Try using a Timer and change the focus after 100 ms, maybe keep the focus because you are still pressing the window so for a test it would be interesting to force the focus a few ms later.

    – eyllanesc
    Nov 17 '18 at 4:44















0















I'm trying to do a seemingly simple thing: after a double-click in one window, I want to open a second top-level (non-modal) window and activate it. However, whatever I do the second window doesn't get activated, the focus remains in the first window.



Here's a minimal example:



import QtQuick 2.11
import QtQuick.Controls 2.4

ApplicationWindow
id: root
height: 480
width: 640
visible: true

MouseArea
anchors.fill: parent
onDoubleClicked:
var w = otherWindowComponent.createObject(root)
w.show()
w.requestActivate() // same effect when removed



Component
id: otherWindowComponent
ApplicationWindow
id: child
width: 400
height: 300

Rectangle
color: "blue"
width: 100
height: 100
focus: true






Am I missing something? Thanks!



UPD: A bit of extra information:



  1. I'm on Windows 10 64-bit

  2. When I replace onDoubleClicked with onClicked, the window gets activated as expected.









share|improve this question
























  • Have your tried calling forceActiveFocus on the create window/item? You can do so in Component.onCompleted

    – Felix
    Nov 16 '18 at 13:17











  • I can't call forceActiveFocus on a Window because it requires an Item. Calling it on the embedded blue Rect doesn't help.

    – Alex Jenter
    Nov 16 '18 at 13:33












  • You can try to call requestActivate() in Component.onCompleted

    – xeco
    Nov 16 '18 at 19:44











  • @AlexJenter How to verify that the focus has not changed?

    – eyllanesc
    Nov 17 '18 at 3:56






  • 1





    @AlexJenter Try using a Timer and change the focus after 100 ms, maybe keep the focus because you are still pressing the window so for a test it would be interesting to force the focus a few ms later.

    – eyllanesc
    Nov 17 '18 at 4:44













0












0








0








I'm trying to do a seemingly simple thing: after a double-click in one window, I want to open a second top-level (non-modal) window and activate it. However, whatever I do the second window doesn't get activated, the focus remains in the first window.



Here's a minimal example:



import QtQuick 2.11
import QtQuick.Controls 2.4

ApplicationWindow
id: root
height: 480
width: 640
visible: true

MouseArea
anchors.fill: parent
onDoubleClicked:
var w = otherWindowComponent.createObject(root)
w.show()
w.requestActivate() // same effect when removed



Component
id: otherWindowComponent
ApplicationWindow
id: child
width: 400
height: 300

Rectangle
color: "blue"
width: 100
height: 100
focus: true






Am I missing something? Thanks!



UPD: A bit of extra information:



  1. I'm on Windows 10 64-bit

  2. When I replace onDoubleClicked with onClicked, the window gets activated as expected.









share|improve this question
















I'm trying to do a seemingly simple thing: after a double-click in one window, I want to open a second top-level (non-modal) window and activate it. However, whatever I do the second window doesn't get activated, the focus remains in the first window.



Here's a minimal example:



import QtQuick 2.11
import QtQuick.Controls 2.4

ApplicationWindow
id: root
height: 480
width: 640
visible: true

MouseArea
anchors.fill: parent
onDoubleClicked:
var w = otherWindowComponent.createObject(root)
w.show()
w.requestActivate() // same effect when removed



Component
id: otherWindowComponent
ApplicationWindow
id: child
width: 400
height: 300

Rectangle
color: "blue"
width: 100
height: 100
focus: true






Am I missing something? Thanks!



UPD: A bit of extra information:



  1. I'm on Windows 10 64-bit

  2. When I replace onDoubleClicked with onClicked, the window gets activated as expected.






qt qml qt5 qtquick2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 4:50









eyllanesc

84.6k103562




84.6k103562










asked Nov 16 '18 at 6:23









Alex JenterAlex Jenter

2,66032553




2,66032553












  • Have your tried calling forceActiveFocus on the create window/item? You can do so in Component.onCompleted

    – Felix
    Nov 16 '18 at 13:17











  • I can't call forceActiveFocus on a Window because it requires an Item. Calling it on the embedded blue Rect doesn't help.

    – Alex Jenter
    Nov 16 '18 at 13:33












  • You can try to call requestActivate() in Component.onCompleted

    – xeco
    Nov 16 '18 at 19:44











  • @AlexJenter How to verify that the focus has not changed?

    – eyllanesc
    Nov 17 '18 at 3:56






  • 1





    @AlexJenter Try using a Timer and change the focus after 100 ms, maybe keep the focus because you are still pressing the window so for a test it would be interesting to force the focus a few ms later.

    – eyllanesc
    Nov 17 '18 at 4:44

















  • Have your tried calling forceActiveFocus on the create window/item? You can do so in Component.onCompleted

    – Felix
    Nov 16 '18 at 13:17











  • I can't call forceActiveFocus on a Window because it requires an Item. Calling it on the embedded blue Rect doesn't help.

    – Alex Jenter
    Nov 16 '18 at 13:33












  • You can try to call requestActivate() in Component.onCompleted

    – xeco
    Nov 16 '18 at 19:44











  • @AlexJenter How to verify that the focus has not changed?

    – eyllanesc
    Nov 17 '18 at 3:56






  • 1





    @AlexJenter Try using a Timer and change the focus after 100 ms, maybe keep the focus because you are still pressing the window so for a test it would be interesting to force the focus a few ms later.

    – eyllanesc
    Nov 17 '18 at 4:44
















Have your tried calling forceActiveFocus on the create window/item? You can do so in Component.onCompleted

– Felix
Nov 16 '18 at 13:17





Have your tried calling forceActiveFocus on the create window/item? You can do so in Component.onCompleted

– Felix
Nov 16 '18 at 13:17













I can't call forceActiveFocus on a Window because it requires an Item. Calling it on the embedded blue Rect doesn't help.

– Alex Jenter
Nov 16 '18 at 13:33






I can't call forceActiveFocus on a Window because it requires an Item. Calling it on the embedded blue Rect doesn't help.

– Alex Jenter
Nov 16 '18 at 13:33














You can try to call requestActivate() in Component.onCompleted

– xeco
Nov 16 '18 at 19:44





You can try to call requestActivate() in Component.onCompleted

– xeco
Nov 16 '18 at 19:44













@AlexJenter How to verify that the focus has not changed?

– eyllanesc
Nov 17 '18 at 3:56





@AlexJenter How to verify that the focus has not changed?

– eyllanesc
Nov 17 '18 at 3:56




1




1





@AlexJenter Try using a Timer and change the focus after 100 ms, maybe keep the focus because you are still pressing the window so for a test it would be interesting to force the focus a few ms later.

– eyllanesc
Nov 17 '18 at 4:44





@AlexJenter Try using a Timer and change the focus after 100 ms, maybe keep the focus because you are still pressing the window so for a test it would be interesting to force the focus a few ms later.

– eyllanesc
Nov 17 '18 at 4:44












1 Answer
1






active

oldest

votes


















1














Maybe it's a Windows bug, in Linux it works correctly. So a workaround would be to set the focus with a Timer a few milliseconds after opening the window.






share|improve this answer






















    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',
    autoActivateHeartbeat: false,
    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%2f53332510%2fhow-to-open-new-window-after-doubleclick-so-that-it-becomes-active%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Maybe it's a Windows bug, in Linux it works correctly. So a workaround would be to set the focus with a Timer a few milliseconds after opening the window.






    share|improve this answer



























      1














      Maybe it's a Windows bug, in Linux it works correctly. So a workaround would be to set the focus with a Timer a few milliseconds after opening the window.






      share|improve this answer

























        1












        1








        1







        Maybe it's a Windows bug, in Linux it works correctly. So a workaround would be to set the focus with a Timer a few milliseconds after opening the window.






        share|improve this answer













        Maybe it's a Windows bug, in Linux it works correctly. So a workaround would be to set the focus with a Timer a few milliseconds after opening the window.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 5:06









        eyllanesceyllanesc

        84.6k103562




        84.6k103562





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332510%2fhow-to-open-new-window-after-doubleclick-so-that-it-becomes-active%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            Evgeni Malkin