QCompleter, complete with images



  • Hello again ... I have a problem, I want to make an application that inserts images in a QTextEdit and I want that when they are inserted 3 images at least, complete with other predetermined images. The problem is that I have no idea how to implement a completer that will allow me to do this.



  • Can you explain how the inserted images will be used to 'complete' to add the other images? Can you give a concrete example by describing what the inserted images contain and what the 'completed' images will contain?



  • @mchinand
    I'm doing a hieroglyphic translator. The hieroglyphs have a classification, a name. Then, as you insert a glyph, it is saved in a list and as the hieroglyphs are part of a type of writing they can be completed and I want to use this so I do not have to type a new word in the line of writing



  • @Blaster said in QCompleter, complete with images:

    inserts images in a QTextEdit
    [...]
    I'm doing a hieroglyphic translator

    hieroglyphics are covered by unicode (for example: https://unicode-table.com/en/#egyptian-hieroglyphs) so you can use normal UTF-8 text, no need for images

    The problem is that I have no idea how to implement a completer

    Create a QStandardItemModel with just 1 column, set the Qt::EditRole to the actual hieroglyphic and the Qt::UserRole to the classification/name then set the completionRole of the QCompleter to Qt::UserRole



  • @VRonin
    Thanks, but I don't know how to insert de unicode text into a QTextEdit.

    @VRonin said in QCompleter, complete with images:

    Create a QStandardItemModel with just 1 column, set the Qt::EditRole to the actual hieroglyphic and the Qt::UserRole to the classification/name then set the completionRole of the QCompleter to Qt::UserRole

    Can you show me how I do that?



  • @Blaster said in QCompleter, complete with images:

    Thanks, but I don't know how to insert de unicode text into a QTextEdit

    You don't have to do anything, you can already copy/paste hieroglyphics in QTextEdit. to explicitly insert a character you can use textEdit->cursor().insertHtml("𓀀"); (maybe you'll need to change the font to something that has those characters, maybe this one)

    Can you show me how I do that?

    QAbstractItemModel* model=new QStandardItemModel(this);
    model->insertColumn(0);
    for(uint i=0xF09390AE; i>=0xF0938080;--i){
    model->insertRow(0);
    model->setData(model->index(0,0),QChar(i));
    model->setData(model->index(0,0),QStringLiteral("Description for code %1").arg(i,0,16),Qt::UserRole);
    }
    completer->setModel(model);
    completer->setCompletionRole(Qt::UserRole);
    


  • @VRonin
    I was checking the hieroglyphs which are in unicode and are not all, so I can't use them



  • I'm not an expert in Egyptian languages so I'll take your word for it, all you have to do then is instead of QChar(i) you'll have QImage(/*...*/) and the loop will be on your set of hieroglyphics. and use cursor().insertImage instead of cursor().insertHtml



  • @VRonin
    QCompleter does not show me anything, no image, just a blank box


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.