[solved] How to set the focus to a new widget dynamically added to the main Dialog ?
-
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. -
wrote on 9 Apr 2014, 08:07 last edited by
Hi,
Thank a lot, effectively giving the focus to the lpCustomWdg ( setfocus() ) and then setting focus proxy work properly !
Xavier
-
Great, please prepend [Solved] to the title of the thread to let others know there's an answer here.
-
wrote on 9 Apr 2014, 10:25 last edited by
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 !
-
Sorry, I can't help you with Qt3. I'm too young I guess ;)
-
wrote on 9 Apr 2014, 15:04 last edited by
Hi
So I'm looking for an old QT3 guru to solve my problem ;)
Thank you
-
Hi,
AFAIR, this should work the same, what OS are you running on ?
-
wrote on 10 Apr 2014, 14:27 last edited by
Yes it should ! working on ... XP and with vs2005...don't laught ! ;)
-
wrote on 10 Apr 2014, 15:01 last edited by
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 ! -
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 :)
11/11