Results 1 to 2 of 2

Thread: Force focus to a QTabWidget page's widget

  1. #1
    Join Date
    Nov 2006
    Thanked 14 Times in 5 Posts
    Qt products
    MacOS X Unix/X11 Windows

    Default Force focus to a QTabWidget page's widget

    So I'm back asking for help with yet another problem I've got an inherited QTabWidget that has several pages. Each page contains a QWidget which holds a few other non-gui objects and a single QTextEdit as the only GUI object. I'm trying to keep it so that when a tab is removed and another tab is set as the current one, that new current tab's QTextEdit has keyboard focus. Right now with the code I have, when I delete a tab, the new one is correctly set, but the focus is on some unknown item.

    The first time I press the tab key, the QTabBar gets focus, allowing me to press the arrow keys to select different tabs. The 2nd time that I press the tab key, the QTextEdit then has focus. I'm trying to get it so that when a tab closes, the next tab that becomes current shows up with the keyboard focus in its QTextEdit.

    Any Ideas on what I'm doing wrong? Here's the main section of code where I'm setting the focus inside my QTabWidget member function ...or trying to

    Qt Code:
    1. // Step 1: Select a new tab and set its console to have focus
    2. //This is the index of the tab to recieve focus after the other one closes
    3. int nextInLine = 0;
    4. if (tabIndex != 0)
    5. nextInLine = tabIndex-1; //tab to the left found
    6. else if ( count() > 1) //There are at least 2 tabs before tab removal
    7. nextInLine = 1; //tab to the right found
    8. //else, we will be left with only one tab
    10. this->setCurrentIndex(nextInLine); //Set new current tab
    11. QWidget *pWidget = ( widget(nextInLine));
    12. if (pWidget)
    13. this->setCurrentWidget( pWidget); //Move the focus to the tab's page (console)
    15. //Step 2: Execute the old tab, right in the temple... it'll be quick
    16. removeTab(tabIndex); //Removes the tab from the display
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2007
    Szczecin, Poland
    Thanked 11 Times in 8 Posts
    Qt products

    Default Re: Force focus to a QTabWidget page's widget

    Suppose You need to connect some slot to void currentChanged ( int index ) signal and and setFocus to textEdit.
    You can also override page's widgets showEvent and setFocus there.
    See GrEEn (Graphics Effects Environment)
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

Similar Threads

  1. Replies: 4
    Last Post: 13th August 2007, 16:28


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.