How to change the order of tabs in a QTabWidget
-
-
@Tomax63
So you'd like us to look at your original code and figure why it can't find the tab, right?I'll look in a sec. Meanwhile:
qint32 i = 0; ... to = i;
How is
to
ever going to be anything other than0
?Although @VRonin wrote
tabwidget->tabBar()->move(from,to);
, I only actually seevoid QTabBar::moveTab(int from, int to)
(https://doc.qt.io/qt-5/qtabbar.html#moveTab). from & to are integer positions, so do yourself a favor and start by replacing yourforeach (QString v, tab_sequenz.split(";"))
with an old-fashionedfor
loop counter so that it's easy to get number positions.... -
@Tomax63
So I think you are saying yourw = ui->my_tabwidget->findChild<QTabWidget *>(v); //get the necessary widget
is not finding the tab by name. That would imply one of:
- The name is not right.
- The matching tab is not currently in the widget.
So do a little digging. What tabs are actually there? What are their names and what are you searching for? If necessary, just do the iteration in your own code to see what's going on. In any case, you're going to need the tab's index to pass to
move()
, so fromfindChild()
you're going to have re-look up the result in the tabs, you might be best off doing it yourself retuning an index number in the first place.... -
I made it.
void MainWindow::restore_tab_seq(QString tab_sequenz){ QStringList v = tab_sequenz.split(";"); qint32 i = 0, j = 0, k = v.count(); for(i=0; i<k; i++){ for (j=0; j<ui->registerkarten->tabBar()->count(); j++){ if (ui->registerkarten->tabBar()->tabText(j).toStdString() == v[i].toStdString()){ ui->registerkarten->tabBar()->moveTab(j, i); } } } } Thanks for your help, mates.
-
Hi,
Why are you using
toStdString
to compare two QStrings ?