Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to focus on new tab?

Tags:

qt4

I was able to add a new tab using qtabwidget->addTab ( newtab, title );

But is it possible to focus on this tab in my code?

Thanks

like image 803
echo Avatar asked Dec 19 '10 09:12

echo


People also ask

How do I focus a tab in Chrome?

Focus Mode in Chrome Make sure you run Google Chrome Canary and that the browser is up to date. Load chrome://flags/#focus-mode. Set the flag to Enabled. Restart Google Chrome.

How do I change my browser focus from one tablet to another?

The keyboard shortcut Cmd + Shift + A (Mac) or Alt + Shift + A (Windows) is the easiest way to switch between tabs in Chrome. This shortcut pulls up a sidebar of your recent tabs.


2 Answers

'setCurrentWidget' or 'setCurrentIndex' will do the job.

You can use either the pointer to the added widget or a numeric index.

See:

http://doc.qt.io/qt-5/qtabwidget.html#setCurrentWidget

http://doc.qt.io/qt-5/qtabwidget.html#currentIndex-prop

For example, if you have a tab widget with say 3 tabs, you can focus on the 2nd tab like this:

ui->tabWidget->setCurrentIndex(1);

If you just want to use the pointer to your widget (MyWidget of type QWidget) then here is another example:

MyWidget* pointerToMyWidgetInTab = new MyWidget();
ui->tabWidget->addTab(pointerToMyWidgetInTab,"Tab2")
ui->tabWidget->setCurrentWidget(pointerToMyWidgetInTab2);
like image 125
Michalis Avatar answered Oct 04 '22 20:10

Michalis


Count the total number of tabs and set the last one:

ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);
like image 31
Sigur Avatar answered Oct 04 '22 20:10

Sigur