hmm ok, I made something like this:
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
ui->tabWidget->setContextMenuPolicy(Qt::CustomContextMenu);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
ui->tabWidget->setContextMenuPolicy(Qt::CustomContextMenu);
}
To copy to clipboard, switch view to plain text mode
And:
void MainWindow
::on_tabWidget_customContextMenuRequested(const QPoint & pos
) {
QTabBar * tabBar
= qobject_cast<QTabBar
*>
(ui
->tabWidget
->childAt
(pos
));
if (!tabBar)
return;
QPoint pos2
= tabBar
->mapFromParent
(pos
);
int tabIndex = tabBar->tabAt(pos2);
qDebug() << tabIndex;
}
void MainWindow::on_tabWidget_customContextMenuRequested(const QPoint & pos)
{
QTabBar * tabBar = qobject_cast<QTabBar *>(ui->tabWidget->childAt(pos));
if (!tabBar)
return;
QPoint pos2 = tabBar->mapFromParent(pos);
int tabIndex = tabBar->tabAt(pos2);
qDebug() << tabIndex;
}
To copy to clipboard, switch view to plain text mode
So the tabIndex contains index of tab if you click right mouse button on the tab bar of tab widget. Then you can show the menu appriopriate to the tab index. You can make some public function returning the menu from the widget set on tab page.
Hmm maybe there's some easier solution but I dont know it :P
Bookmarks