[Qt-interest] QTreeView/QListView cell only copyability when it contains a QString?

Niels Dekker - no reply address invalid at this.is.invalid
Tue Jan 26 11:38:28 CET 2010


It seems to me that the user can only copy (Ctrl+C) the contents of a cell 
from a QTreeView or a QListView if the cell contains a QString. Other data 
types, like int and QDateTime, seem uncopyable to the user. If so, is this a 
bug?

Example: Suppose a model has 3 rows, having a QString, an int and a 
QDateTime:

  QVariant MyModel::data(const QModelIndex& modelIndex, int role) const
  {
    if ( role == Qt::DisplayRole )
    {
      switch( modelIndex.row() )
      {
        case 0: return tr("This is copyable! Select the cell, Ctrl+C");

        // Unfortunately the user cannot copy the int or the datetime:
        case 1: return 42;
        case 2: return QDateTime::currentDateTime();
      }
    }
    return QVariant();
  }

Do ui.treeView->setModel to this model. Run the application. Select a cell 
from the tree view and press Ctrl+C. Paste the result into a text editor to 
see the result. Does it work? On my machine, the second and third row cannot 
be copied.  (I have Qt 4.6.1 installed on Windows XP SP2.)

Are you able to reproduce this issue?  Is there a way to make cells of any 
data type copyable? Otherwise I hope the issue will be fixed soon.

Kind regards,

  Niels
-- 
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center 





More information about the Qt-interest-old mailing list