tags:

views:

53

answers:

3

I searched for hours but I found nothing about that.

I have a qtablewidget and by pressing CTRL while clicking on a column header a would like to mark the whole column content. To get the column index is not the problem: there is a sectionPressed signal which gives me the current index I clicked. Can anybody help?

+1  A: 

The state of the keyboard modifier keys can be found by calling the modifiers() function, inherited from QInputEvent.

http://doc.qt.nokia.com/4.6/qmouseevent.html

František Žiačik
I know but I have no object within the associated slot to sectionPressed other then the column index. No event, no sender, nothing.
tfl
Maybe you could save the modifiers state in mouseReleaseEvent which should occur before the signal.
František Žiačik
A: 

this is really annoying, I have to install an eventFilter and remove the sectionPressed handler

ui->tableWidget->horizontalHeader()->viewport()->installEventFilter(this);

Within the eventFilter I can check wether a key was pressed like so

bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
    if(event->type() == QEvent::MouseButtonPress)
    {
        if(Qt::ControlModifier == QApplication::keyboardModifiers())
        {
            QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
            if(mouseEvent)
            {
                if(mouseEvent->button()== Qt::LeftButton)
                {
                    ui->tableWidget->selectColumn(ui->tableWidget->itemAt(mouseEvent->pos())->column());
                    return true;
                }
            }
        }
    }

    return QWidget::eventFilter(object,event);
}
tfl
A: 

Try QApplication::keyboardModifiers() which is always available.

Roku
i found it allready
tfl