Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextEdit align inline image with text

QTextEdit align inline image with text

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by Rory_1
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • R Rory_1

      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?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • jsulmJ jsulm

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

        R Offline
        R Offline
        Rory_1
        wrote on last edited by Rory_1
        #3

        @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.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yao_njjjjjj
          wrote on last edited by
          #4

          have you solve the alignment issue

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved