Results 1 to 2 of 2

Thread: QTableWidgetItem: setData or setText?

  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidgetItem: setData or setText?

    Hello,
    I am wondering what's the difference between

    Qt Code:
    1. myTableWidgetItem->setData(Qt::DisplayRole, "hello");
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. myTableWidgetItem->setText("hello");
    To copy to clipboard, switch view to plain text mode 

    when adding new items to a QTableWidget... I tried both approaches and cannot tell the difference. Which one should I choose?

    (edit: also, it looks like setTextAlignment() works on both)

    Thank you

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidgetItem: setData or setText?

    there is no difference between these two code snippets.
    since
    Qt Code:
    1. inline void QTableWidgetItem::setText(const QString &atext)
    2. { setData(Qt::DisplayRole, atext); }
    To copy to clipboard, switch view to plain text mode 
    the last one is simpler.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following 2 users say thank you to spirit for this useful post:

    frankiefrank (10th January 2011), mattc (5th January 2010)

Similar Threads

  1. setData fails in QSqlRelationalTableModel
    By thePoet in forum Qt Programming
    Replies: 6
    Last Post: 8th July 2009, 04:27
  2. QSqlTableModel and possible bug with setData?
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2009, 21:43
  3. QwtPolarCurve setData()---help needed
    By swamyonline in forum Qwt
    Replies: 2
    Last Post: 6th August 2008, 07:30
  4. setData()
    By starcontrol in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 08:54
  5. setData()
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2008, 12:51

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.