Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Stymied with use of setTabOrder



  • I have searched the archives for useful information, but was unable to find solution to a taborder problem in an app I have been developing.

    I suspect I have some basic misconception about the use of setTaboOrder and would very much appreciate a pointer to some example or demo that illustrates something more than a trivial use of setTabOrder.

    The basic problem (as many others have noted) is that the taborder effective in an application is determined by the order in which I create a bunch of widgets. However, in my application, I often re-sort the inventory. Unfortunately, the original taborder is maintained after sorting, leading to seemingly random taborder. I'd really prefer to tab through the table in the order the inventory is displayed, not the order in which it was created.

    setTabOrder seems designed for this purpose, but it doesn't seem to have any effect, at least in my implementation. Some sketchy details are provided below of the overall structure of the app, but are likely not necessary for helping me get pointed in a better direction.

    IMPORTANT NOTE: The basic app functions very well apart from the tab order issues.

    The application is basically an inventory that is displayed as a table. Each item in the inventory occupies one row of the table, and each item as a fixed set of editable fields that are displayed in the columns. There are controls for which fields of the items are displayed/hidden, and there are controls to sort the inventory by various item fields and to display/hide items that do/don't match search criteria.

    Each inventory item is represented by a widget that contains the required edit fields, let's call it the itemEditorWidget. That widget is a QGridLayout with only one row, but multiple columns for the edit fields. The full inventory is another QGridLayout with only one column containing an itemEditorWidget and a row for each item (it is likely that I could have done this with other box layouts, but QGridLayout gave me the control I needed to get all the stretching to work right).

    All of this is contained in a QScrollArea, which is surrounded by a bunch of other widgets. Because some of these other widgets are created after the initial batch of itemEditorWidgets, any new inventory items really confuse the ultimate tab order. You tab through the initial itemEditorWidgets, then through some other seemingly random widgets, then back into some subsequently itemEditorWidgets, then back into some other dynamically created widgets, then back into more subsequently added itemEditorWidgets, etc, etc, etc.

    MY ATTEMPTED USE OF setTabOrder was very simple. After resorting the table, I tried to use setTabOrder to connect the last edit field of one itemEditorWidget to the first field of the next itemEditorWidget. But that had no apparent effect. I also attempted to use setTabOrder within an itemEditorWidget to scramble the taborder within the widget - also with no effect.

    Hence, I'm pretty sure I'm just doing something dumb that keeps it from working.

    Any suggestions where to look for wisdom?


  • Lifetime Qt Champion

    Please provide a minimal example - since setTabOrder() is widely used I simply would say - it works - so there must be another reason why it does not work for you.



  • I will be happy to provide a "minimal example" of what I do. However, be forewarned that this could be at best a skeleton of what is going on.

    Since setTabOrder is so commonly used, it seems that giving me a non-trivial example of what works would be a quicker way to my solution. That way the onus is on me, and not someone else, to understand the example.

    For the barest skeleton,


    typedef QList<QWidget*> tEditor;
    typedef QList<type1*> tEditorList;
    typedef QList<QStringList> inventory;

    for (int i=0 ; i<inventory.count() ; i++)
    {
    tEditor* = new tEditor;
    tEditor->setup(inventory.at(i));
    tEditorList.push_back(tEditor);
    }

    idxmax = tEditorList.at(0).count()-1;

    sort(&inventory);

    for (int i=1 ; i<inventory.count() ; i++)
    {
    QWidget* last = inventory.at(i-1).at(idxmax);
    QWidget* next = inventory.at(i) .at(0);
    setTabOrder(last, next);
    }



Log in to reply