Skip to content

Instantly share code, notes, and snippets.

@mistic100
Created September 4, 2016 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mistic100/16880f15bfe3a7de8aa468da7140ab40 to your computer and use it in GitHub Desktop.
Save mistic100/16880f15bfe3a7de8aa468da7140ab40 to your computer and use it in GitHub Desktop.
[Qt/C++] QTabWidget which allow to set the current tab by its name
#ifndef QTABWIDGETEXT
#define QTABWIDGETEXT
#include <QTabWidget>
/**
* @brief QTabWidget which allow to set the current tab by its name
*/
class QTabWidgetExt : public QTabWidget
{
Q_OBJECT
public:
QTabWidgetExt(QWidget* _parent = 0) : QTabWidget(_parent) {}
void setCurrentTab(const QString &_tabName)
{
foreach (QWidget* child, findChildren<QWidget*>())
{
if (child->objectName() == _tabName)
{
setCurrentIndex(indexOf(child));
}
}
}
};
#endif // QTABWIDGETEXT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment