Important: Please read the Qt Code of Conduct -

[SOLVED] Synchronizing tab ordering with button ordering

  • Dear readers,

    In my application I have some function that requires a whole bunch of parameters. There is a tabbed settings panel, that can be used to configure four 'presets'. Additionally there is a 'start' button for each of these four parameter configurations. These buttons are (currently) in a HBoxLayout.

    I'd like these buttons to follow the ordering of the tabs in the settings panel. I.e. if I move the second tab the first location, the second button should move in front inside the horizontal layout as well.

    Is anyone aware of existing code that already does it? Otherwise, how could I do this? (in particular I don't have a clue how to reorder the buttons in the horizontal layout, if at all possible)

    For bonus, I'd like to be able to update the layout of the buttons already while dragging the tab, so don't wait for the tabMoved signal before updating the button ordering.

  • Lifetime Qt Champion


    AFAIK there's nothing ready made for that. Without the bonus part you can simply take the button out and use insert to put it at the right place back in.

    Hope it helps

  • Hej,

    Thanks for the reply. It confirmed my suspicions.

    What I didn't realize before however, is that the tabMoved signal is actually emitted independent on whether the mouse is still down or not. GREAT! I created a very simple prototype, and as it turns out, I get everything I want, including the bonus feature by simply connecting to QTabBar::tabMoved and in the slot writing a line along the lines of the following:

    m_view.buttonContainer->insertItem(to, m_view.buttonContainer->takeAt(from));

    Here m_view is an instance of the prototype widget I created, buttonContainer is a HBoxLayout that holds the same number of buttons as the tab bar.

  • Lifetime Qt Champion

    Great !

    Thanks for sharing your solution :)