Ejemplo n.º 1
0
void UserWidget::mouseMoveEvent( QMouseEvent *event){
  QTabBar *wid = tabBar();
  if(wid==0){ return; } //invalid widget found
  QPoint relpos = wid->mapFromGlobal( this->mapToGlobal(event->pos()) );
  //qDebug() << "Mouse Move Event: " << event->pos().x() << event->pos().y() << relpos.x() << relpos.y() << wid->width() << wid->height();
  if(wid && wid->tabAt(relpos) != -1){
    qDebug() << " - Mouse over tab";
    this->setCurrentIndex( wid->tabAt(relpos) );
  }
}
Ejemplo n.º 2
0
void MainTab::mousePressEvent(QMouseEvent* event)
{
    if(event->buttons() == Qt::MidButton)
    {
        QTabBar* bar = tabBar();
        m_index = bar->tabAt(bar->mapFrom(this, event->pos()));
        closeTab();
    }
    QTabWidget::mousePressEvent(event);
}
Ejemplo n.º 3
0
void DocumentTabs::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::MidButton)
    {
        QTabBar *tabs = tabBar();
        removeTab(tabs->tabAt(event->pos()));
    }

    QTabWidget::mousePressEvent(event);
}
Ejemplo n.º 4
0
void MainTab::contextMenuEvent(QContextMenuEvent* event)
{
    QTabBar* bar = tabBar();

    m_index = bar->tabAt(bar->mapFrom(this, event->pos()));

    if(m_index < 0)
        return;

    QAction* action;
    QMenu menu(this);

    if(m_index > 3)
    {
        action = menu.addAction(tr("Close tab"));
        connect(action, SIGNAL(triggered()), this, SLOT(closeTab()));
    }

    action = menu.addAction(tr("Close all tabs"));
    connect(action, SIGNAL(triggered()), this, SLOT(closeAllTabs()));

    menu.exec(mapToGlobal(event->pos()));
}
Ejemplo n.º 5
0
bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e)
{
    QTabBar* bar = qobject_cast<QTabBar*>(o);
    if (bar && (e->type() == QEvent::MouseMove || e->type() == QEvent::Leave)) {
        QMouseEvent* event = static_cast<QMouseEvent*>(e);
        const QString old_hovered_tab = bar->property("tab_hover").toString();
        const QString hovered_tab = e->type() == QEvent::Leave ? QString() : bar->tabText(bar->tabAt(event->pos()));
        bar->setProperty("tab_hover", hovered_tab);

        if (old_hovered_tab != hovered_tab) {
            bar->update();
        }
    }

    return false;
}