Results 1 to 3 of 3

Thread: QTableWidgetItem and QToolButton : who's my neighbour?

  1. #1
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question QTableWidgetItem and QToolButton : who's my neighbour?

    Hi,

    I'm starting with Qt and CPP. Here is my problem : I have a QTableWidget with data and I want to add a button in the first cell of every row to delete the row.
    I subclassed the QToolButtonclass and wanted to add as a attribute a pointer to the neighbour cell.
    The idea was that the user could delete randomly any row and every deleteRowButton would know its row with neighbourCell->row() (the widget inserted a cell using setItem() can't know the current row, am I right?).

    Here is my code :
    the creation of the row with the creation of the deleteRowButton, located in my mainwindow (airflowcalculator.cpp) :
    Qt Code:
    1. tableItem->insertRow(newRow);
    2. tableWidgetEraseItem = new deleteRowButton(*tableWidgetName);
    3. tableItem->setCellWidget(newRow, 0, tableWidgetEraseItem);
    4. tableWidgetName = new QTableWidgetItem("my name");
    5. tableItem->setItem(newRow, 1, tableWidgetName);
    To copy to clipboard, switch view to plain text mode 

    the slot to remove the row in my mainwindow (airflowcalculator.cpp)
    Qt Code:
    1. void airflowCalculator::removeAVComponent(int row)
    2. {
    3. tableItem->removeRow(row);
    4. tableItem->selectRow(tableItem->currentRow());
    5. }
    To copy to clipboard, switch view to plain text mode 

    The deleteRowButton class (deleterowbutton.cpp)
    Qt Code:
    1. #include "deleterowbutton.h"
    2. #include <QIcon>
    3.  
    4. deleteRowButton::deleteRowButton(const QTableWidgetItem & neighbourCellTemp)
    5. {
    6. neighbourCell = neighbourCellTemp;
    7. setIcon(QIcon(":/images/delete.png"));
    8. connect(this, SIGNAL(clicked()),this, SLOT(deleteRowSlot()));
    9. }
    10.  
    11. void deleteRowButton::deleteRowSlot()
    12. {
    13. emit deleteRow(neighbourCell->row());
    14. }
    To copy to clipboard, switch view to plain text mode 

    Of course, I suspect the argument passing to the deleteRowButton but I'm a little bit lost after having tried with pointers and references

    Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTableWidgetItem and QToolButton : who's my neighbour?

    Quote Originally Posted by gruzlor View Post
    (the widget inserted a cell using setItem() can't know the current row, am I right?).
    I'm not sure what you mean, but newRow is the row? So it does know the row?

    Note that any item can report its current row:
    http://doc.qt.nokia.com/4.7/qtablewidgetitem.html#row

    Qt Code:
    1. ...
    2. tableWidgetEraseItem = new deleteRowButton(*tableWidgetName);
    3. ...
    4. tableWidgetName = new QTableWidgetItem("my name");
    5. ...
    To copy to clipboard, switch view to plain text mode 
    This logic seems wrong. Shouldn't tableWidgetName be created before tableWidgetEraseItem?

  3. #3

    Default Re: QTableWidgetItem and QToolButton : who's my neighbour?

    QToolButton class provides quick access to commands or options, usually used in a QToolBar. QToolButton supports self-consciousness. In automatic mode to rise, the button draws a 3D frame when you move your mouse over it. The function is automatically activated when the button is used in a QToolBar. This is also udes in deletion of any.

Similar Threads

  1. Qt Designer Icons in QToolButton
    By pdevroede in forum Qt Tools
    Replies: 2
    Last Post: 21st December 2010, 22:33
  2. QToolButton & setStyleSheet
    By kavinsiva in forum Newbie
    Replies: 1
    Last Post: 3rd June 2010, 15:52
  3. QToolButton margins
    By bjoernbg in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2008, 10:28
  4. Need help with QToolButton
    By philipp1 in forum Qt Programming
    Replies: 12
    Last Post: 27th October 2006, 16:37
  5. Need help with QToolButton
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2006, 15:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.