QTextEdit align inline image with text



  • I am building a token editor to construct the file path to store images. I have tokens for dates etc that I drop onto a subclassed QTextEdit to combine with text. A sample currently looks like this:

    alt text

    As you can see I have a vertical alignment issue. I have managed to set the line height using

    QTextBlockFormat blockFormat;
    blockFormat.setLineHeight(30, QTextBlockFormat::FixedHeight);
    textCursor().setBlockFormat(blockFormat);
    

    I have tried to change the vertical alignment of the text using

    QTextCharFormat charFormat;
    charFormat.setVerticalAlignment(QTextCharFormat::AlignTop);
    textCursor().setCharFormat(charFormat);
    

    However, this does not change the vertical alignment. I was hoping to change the vertical alignment of the text and then tweak the line height to get a precise match between the image and the text.

    Any tips on how I can accomplish this? I started to look at QTextLayout. Would that work?


  • Moderators

    @Rory_1 Why do you use images for that? You could simply fill in "C:/YYYY-MM-DD/Location" as text.



  • @jsulm said in QTextEdit align inline image with text:

    @Rory_1 Why do you use images for that? You could simply fill in "C:/YYYY-MM-DD/Location" as text.

    Because then the user could edit the tokens. The tokens are dragged onto the textedit to create whatever path the users wants - that is not as easy with text since the user can change the text. I know that I could format the tokens and then ignore key events for the formatted text to make them "read only". This approach, using images, avoids all that stuff - all I need to do is get the alignment right.

    If you have a better way to do tokens I'd consider that for sure, but I'm also interested in the alignment issue.


Log in to reply
 

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