You MUST subclass QTabWidget because you have to subclass QTabBar and then use QTabBar::setTabBar that is protected.
MyTabWidget.cpp
#include "MyTabWidget.h"
#include "MyTabBar.h"
MyTabWidget
::MyTabWidget(QWidget *parent
) :{
MyTabBar* myTab = new MyTabBar;
setTabBar (myTab);
}
#include "MyTabWidget.h"
#include "MyTabBar.h"
MyTabWidget::MyTabWidget(QWidget *parent) :
QTabWidget(parent)
{
MyTabBar* myTab = new MyTabBar;
setTabBar (myTab);
}
To copy to clipboard, switch view to plain text mode
MyTabBar.cpp
#include "MyTabBar.h"
#include <QtGui/QInputDialog>
#include <QtGui/QMouseEvent>
MyTabBar
::MyTabBar(QWidget *parent
) :{
}
{
if (e->button () != Qt::LeftButton) {
QTabBar::mouseDoubleClickEvent (e
);
return;
}
int idx = currentIndex ();
bool ok = true;
this, tr ("Change Name"),
tr ("Insert New Tab Name"),
tabText (idx),
&ok);
if (ok) {
setTabText (idx, newName);
}
}
#include "MyTabBar.h"
#include <QtGui/QInputDialog>
#include <QtGui/QMouseEvent>
MyTabBar::MyTabBar(QWidget *parent) :
QTabBar(parent)
{
}
void MyTabBar::mouseDoubleClickEvent(QMouseEvent *e)
{
if (e->button () != Qt::LeftButton) {
QTabBar::mouseDoubleClickEvent (e);
return;
}
int idx = currentIndex ();
bool ok = true;
QString newName = QInputDialog::getText (
this, tr ("Change Name"),
tr ("Insert New Tab Name"),
QLineEdit::Normal,
tabText (idx),
&ok);
if (ok) {
setTabText (idx, newName);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks