0

actually I build an Dialog from an .ui file for displaying all shortcuts in my application. I have an QTableWidget with normal items (cells with qString) and an QPushButton in a cell. My SelectionBehavior is QAbstractItemView::SelectRows and i add an eventFilter to my table(->viewport). If I select a cell, the full row is selected, as expected. But if i mousehover the cell with the button, this cell take the selection. How can i avoid this behavior?

mUiShortcutMapperDialog->tableShortcuts->setRowCount(mActionList.size());

    mUiShortcutMapperDialog->tableShortcuts->setColumnCount(4);
    QStringList headerLabels;
    int row = 0;
    for (std::list<QAction*>::const_iterator iterator = mActionList.cbegin(); iterator != mActionList.cend(); iterator++)
    {
        // Add Name to row
        headerLabels.append(QString( QVariant(row +1).toString()));

        QPushButton* _btn = new QPushButton("reset");
        _btn->setMaximumSize(50,20);
        tableShortcuts->setCellWidget(row, 0, _btn);
        tableShortcuts->setItem(row, 0, new QTableWidgetItem(""));

        mUiShortcutMapperDialog->tableShortcuts->setItem(row, 1, new QTableWidgetItem(QString("Edit")));
        QString name = (*iterator)->objectName();
        tableShortcuts->setItem(row, 2, new QTableWidgetItem(name));
        QKeySequence shortcut = (*iterator)->shortcut();
        tableShortcuts->setItem(row, 3, new QTableWidgetItem(shortcut.toString()));

        tableShortcuts->item(row,0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        tableShortcuts->item(row,1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        tableShortcuts->item(row,2)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        tableShortcuts->item(row,3)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);

        row++;
    }
    tableShortcuts->setVerticalHeaderLabels(headerLabels);
    tableShortcuts->viewport()->installEventFilter(this);   // (mk) dunno if this is an good idea, we give the acutal class as eventfilter
    tableShortcuts->setSelectionBehavior(QAbstractItemView::SelectRows);
    tableShortcuts->setMouseTracking(true);
norca
  • 138
  • 1
  • 14
  • i think the key problem is the line setSelectionBehavior(QAbstractItemView::SelectRows); – norca Dec 19 '12 at 16:11
  • if i comment the line tableShortcuts->setCellWidget(row, 0, _btn); everything works fine. but with this the selection react strange. – norca Dec 19 '12 at 16:19
  • we change the design of the window and cancel the button. so my problem isnt existing anymore. but this was really strange behavior – norca Dec 20 '12 at 17:31

0 Answers0