[Qt-interest] problem with signal slot in QTableWidget

Malyushytsky, Alex alex at wai.com
Sat Jun 18 00:51:09 CEST 2011


Have you tried to replace QWidget::mousePressEvent( event );
with: QTableWidget::mousePressEvent( event );
to check if left click works in this case?

Alex


-----Original Message-----
From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Riccardo Roasio
Sent: Friday, June 17, 2011 3:15 AM
To: qt-interest
Subject: [Qt-interest] problem with signal slot in QTableWidget

HI,

i have a class derived from QTableWidget and i would like to catch
when the user click on a cell.

I'm trying to use:

connect(this, SIGNAL(cellClicked(int,int)), this,
SLOT(SetCurrentCell(int,int)));

but it seems not to work.

Should be because i'm also catching mousePressEvent ?

This is the code:


#include "customtablewidget.h"

CustomTableWidget::CustomTableWidget(QString t,Configuration *c)
{
    activeConfiguration=c;
    type=t;

    connect(this, SIGNAL(cellClicked(int,int)), this,
SLOT(SetCurrentCell(int,int)));
}

void CustomTableWidget::mousePressEvent( QMouseEvent * event )
{
    if(event->button()==Qt::RightButton)
    {
        QMenu *tmpMenu=new QMenu(this);

        QAction* newItemAction = new QAction(tr("&Add New"),this);

        connect(newItemAction, SIGNAL(triggered()), this, SLOT(AddNewItem()));

        tmpMenu->addAction(newItemAction);
        tmpMenu->exec(event->globalPos());
    }
    else
    {
        QWidget::mousePressEvent( event );
    }


}

void CustomTableWidget::SetCurrentCell(int r,int c)
{
    int currentRow=r;
    int currentColumn=c;
}

void CustomTableWidget::AddNewItem()
{
    if(type=="INPUT")
    {
        InputItem *tmpInputItem=new InputItem(this);
        tmpInputItem->SetConfiguration(activeConfiguration);

        int maxRows=this->rowCount();
        int maxCols=this->columnCount();
        if(maxCols==0)
        {
            setColumnCount(1);
        }
        this->setRowCount(maxRows+1);
        this->setCellWidget(maxRows,0,tmpInputItem);
        this->scrollToBottom();
    }
    else if(type=="OUTPUT")
    {
        OutputItem *tmpOutputItem=new OutputItem(this);
        tmpOutputItem->SetConfiguration(activeConfiguration);

        int maxRows=this->rowCount();
        int maxCols=this->columnCount();
        if(maxCols==0)
        {
            setColumnCount(1);
        }
        this->setRowCount(maxRows+1);
        this->setCellWidget(maxRows,0,tmpOutputItem);
        this->scrollToBottom();
    }
}


Thanks,
Riccardo
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”


More information about the Qt-interest-old mailing list