Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] How to set the focus to a new widget dynamically added to the main Dialog ?
Forum Updated to NodeBB v4.3 + New Features

[solved] How to set the focus to a new widget dynamically added to the main Dialog ?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on 8 Apr 2014, 16:01 last edited by
    #2

    Hi, welcome to devnet

    You seem to be setting focus proxy but not actually giving it a focus?
    Try to call "setFocus()":http://qt-project.org/doc/qt-5/qwidget.html#setFocus on the lpCustomWdg.

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xaviermartin
      wrote on 9 Apr 2014, 08:07 last edited by
      #3

      Hi,

      Thank a lot, effectively giving the focus to the lpCustomWdg ( setfocus() ) and then setting focus proxy work properly !

      Xavier

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 9 Apr 2014, 10:10 last edited by
        #4

        Great, please prepend [Solved] to the title of the thread to let others know there's an answer here.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xaviermartin
          wrote on 9 Apr 2014, 10:25 last edited by
          #5

          Ok, this work in Qt4, unfortenately same code doesn't make job in Qt3 ! In Qt3 setting the new CustomWdg isn't effective. Yes probably not a lot of people still using Qt3, but me I do !

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 9 Apr 2014, 10:28 last edited by
            #6

            Sorry, I can't help you with Qt3. I'm too young I guess ;)

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xaviermartin
              wrote on 9 Apr 2014, 15:04 last edited by
              #7

              Hi

              So I'm looking for an old QT3 guru to solve my problem ;)

              Thank you

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 9 Apr 2014, 20:42 last edited by
                #8

                Hi,

                AFAIR, this should work the same, what OS are you running on ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xaviermartin
                  wrote on 10 Apr 2014, 14:27 last edited by
                  #9

                  Yes it should ! working on ... XP and with vs2005...don't laught ! ;)

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    xaviermartin
                    wrote on 10 Apr 2014, 15:01 last edited by
                    #10

                    I post a solution :

                    I do not use setFocus() when using Qt3. After the addition of the new custom widget the focus goes (by magic) into the first QLineEdit of the new custom wdg.

                    Then I set the setTabOrder as follow :

                    @
                    setTabOrder(m_lpCustomWdg->lpCheckBoxLastWidgetOfTheCustom, lpNewButton);
                    setTabOrder(m_lpNewButton, m_lpRemoveButton);
                    setTabOrder(m_lpRemoveButton, m_lpCancelButton);
                    setTabOrder(m_lpCancelButton, m_lpOkButton);
                    @

                    so code is : @void QDlg::addNewWdg()
                    {
                    if (! m_newWdgList.isEmpty())
                    {
                    //fill the custom widget with previous value;
                    qCustomWdg* lpLastWidget = m_newWdgList.last();
                    int iStartValue = lpLastWidget ->startValue();
                    int iEndValue = lpLastWidget ->endValue();
                    int iCurrentComboxIndex = lpLastWidget ->currentIndexComboBox();
                    lpCustomWdg = new qCustomWdg(iStartValue, iEndValue, iCurrentComboxIndex, m_Mnemos,this);

                    }
                    else
                    lpCustomWdg = new qCustomWdg(1, 1, 0, m_Mnemos,this);

                    m_newWdgList.append(lpCustomWdg );
                    lpWidgetVboxLayout->addWidget(lpCustomWdg );
                    lpCustomWdg ->show();
                    //if I do not make a setTabOrder after the last widget of the new custom wdg //the focus goes to the first new widget inserted.
                    setTabOrder(m_lpCustomWdg->lpCheckBoxLastWidgetOfTheCustom, lpNewButton);
                    setTabOrder(m_lpNewButton, m_lpRemoveButton);
                    setTabOrder(m_lpRemoveButton, m_lpCancelButton);
                    setTabOrder(m_lpCancelButton, m_lpOkButton);

                    }@
                    A that's doing the job !

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 10 Apr 2014, 20:11 last edited by
                      #11

                      I won't had to work on that beast too ;)

                      Nice catch !

                      Since you found a solution, can you also please update the thread title prepending [solved] ? So other forums users may know :)

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      11/11

                      10 Apr 2014, 20:11

                      • Login

                      • Login or register to search.
                      11 out of 11
                      • First post
                        11/11
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved