Qt World Summit: Submit your Presentation

How to make painter->drawText selectable and NOT editable

  • Hi
    im using Listview item delegetor , and im drowing some texts in the items for example:
    @QString videoTitle = pItem->title();
    QRectF textBox = line.adjusted(PADDING+THUMB_WIDTH, PADDING, -2 * PADDING, -PADDING);
    textBox = painter->boundingRect( textBox, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, videoTitle);
    painter->drawText(textBox, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, videoTitle);

    what i need to add so it will be selectable and NOT editable so i could copy it with my mouse .

  • How about creating editor typed QLineEdit with 'readOnly' property set If you wanna copy part of text ?
    Though the whole text will be copied after selecting cell if you press QKeySquence::Copy(Ctrl-C or CMD-C).

  • Thanks for the replay , can you direct me to example code ?
    what do you mean "editor typed QLineEdit " ?

  • Once you learn ow to use QAbstractItemDelegate class you will know about Its' memeber createEditor(),setEditorData(), and setModelData(). And then you will know how to create your own readonly QLineEdit Editor when select a item in your QAbstratItemView .

Log in to reply