Results 1 to 13 of 13

Thread: Suggestions for particular text format in QTextEdit

  1. #1

    Default Suggestions for particular text format in QTextEdit

    Hi

    Since I'm not very expert in use QT I would to ask for some suggestion regarding a particular text format I would to show using QTextEdit control. My need is to show lines of text in a format like the following:


    AAAA BBBB CCCCC

    ___aaa_____bbbb______cccc


    Please, note that in this example characters '_' are used instead of spaces since I can not obtain such text format using the standard control of this forum editor.

    As you can see the big text "words" have below some small text that must be "centered" with the connected big word over. I don't have a clear idea regarding how to obtain this fomat into QTextEdit. I tried to use html code (<span> and css) but the same html code working in a standar browser don't have the same result in the qt control, I suppose for some unsupported css tag. I could try using tables but how to make tables aligned in the same line? The problem is this format must act like standard text, than if I'll resize the editor window the text must to redistribute correctly.

    Someone can point me in the right direction for make this result?

    Thank you

  2. #2
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: Suggestions for particular text format in QTextEdit

    I'm a bit confused are you trying to make "AAAA BBBB CCCC" lowercase and centered or are you trying to replace spaces with "_"? or are you trying to center the small stuff under the big letters?

    Eidt if you are trying to center the second string you could do something like ->>> void QTextEdit::setAlignment ( Qt::Alignment a ) [slot]
    Sets the alignment of the current paragraph to a. Valid alignments are Qt::AlignLeft, Qt::AlignRight, Qt::AlignJustify and Qt::AlignCenter (which centers horizontally).
    See also alignment(). <<<-

    so someting like QTextEdit::setAlignment(Qt::AlignCenter);
    Last edited by giblit; 25th March 2013 at 22:40.

  3. #3

    Default Re: Suggestions for particular text format in QTextEdit

    Hi

    Sorry, I understand my request is a bit difficult to explain. Basically my need is the third option you said. Regarding the character "_" I used instead of spaces because this forum editor clean each additional speces between words than I can not "format" the words position as I would. In the original version you have to imagine blank spaces instead of "_". Basically each big word must have below a small word centered "inside" the width of the big word itself. This because the small word will be like an "explanation" of the meaning of the "connected" big word above. Big and small words should be a unique block indipendend from any others. Hope to have clarify a bit...

  4. #4
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: Suggestions for particular text format in QTextEdit

    basically replacing all the underscores with spaces is a simple task.
    Qt Code:
    1. QTextEdit textEdit;
    2. QString qstr = "____aaaa____bbbb____cccc";
    3. qstr.replace("_", " ");
    4. textEdit->setText(qstr);
    To copy to clipboard, switch view to plain text mode 
    and as far as centering under the other words you could do something like this
    Qt Code:
    1. QTextEdit textEdit;
    2. QString large = "AAAA BBBB CCCC";
    3. QString small = "aaaa bbbb cccc";
    4. int index;
    5. index = large.indexOf("AAAA");
    6. QTextCursor c(textEdit->textCursor());
    7. c.movePosition(QTextCursor::setPosition(index,QTextCursor::KeepAnchor));
    8. textEdit->setPlainText(small);
    To copy to clipboard, switch view to plain text mode 
    maybe something like that will work

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for particular text format in QTextEdit

    You can always put the words in a table.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6

    Default Re: Suggestions for particular text format in QTextEdit

    Quote Originally Posted by wysota View Post
    You can always put the words in a table.
    This is another way I'm trying to follow. However there are two problems. Currently I'm testing use of QTextCursor and insertTable but I have a problem that, after created a new table, the cursor remain "inside" the table and every new insertion is always inside the first cell, I need a way to move the cursor out of the table for create a new table outside. Since we are on topic can you help me about this problem? However the doubt I have regarding this solution is that, if QTextEdit control use tables as same way as standard html browser do, tables can not be positioned side by side but only one per line. I still was not able to verify...

    By the way I made a picture for clarify better my needed format:

    demo.jpg

    As you cann see "block of words" have to be disposed in multiple lines as normal text but every big word must have the connected small word centered under them...

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for particular text format in QTextEdit

    Maybe you should just state what is the final effect you are trying to achieve? Why are you using QTextEdit, is that some requirement?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8

    Default Re: Suggestions for particular text format in QTextEdit

    No, QTextEdit is the first control I thought to use but is not mandatory. My need is only that these "text blocks" must be act like standard edit control. This mean if I resize the "control" showing these text the block must to redispose automatically as a normal text do (ex. if I decrease the width of the control the blocks on the right must to moved in the line below and so on). The second need is that the text can be selected and copied into clipboard and the control is read only.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for particular text format in QTextEdit

    This would suggest you are dealing with a list of blocks which would suggest QListView or QListWidget to be an ideal solution to your problem. Of course you have to provide a custom delegate for selecting text (unless you're not interested in selecting part of a single block but rather whole block at a time).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10

    Default Re: Suggestions for particular text format in QTextEdit

    Unfortunately I don't think QListView is a good solution mainly because not all the big words will have the same width size. Using the ListView control I have a grid with all the columns sized as the largest width element in the list that is not what I would. Just for a moment forget the presence of the "small words below the big words". In this case this will be a normal editor with standard text written using big font (like this text I'm writing). In add of this standard text every big words will have a small word below. An example could be a text written in a foreign language and below every words the meaning of the word in your language written smaller...

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suggestions for particular text format in QTextEdit

    Quote Originally Posted by Suppaman View Post
    Unfortunately I don't think QListView is a good solution mainly because not all the big words will have the same width size.
    That is not important. Enable wrapping property and have the list flow from left to right.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12

    Default Re: Suggestions for particular text format in QTextEdit

    I'll try to follow this way too, but before I would to verify if really tables can not be aligned into the same line in QTextEdit. Someone can confirm? In add I still have the problem above using QTextTable. After inserted new table using insertTable() the cursor remain inside the first cell, how can I move the cursor outside the table just created?

    Thank you for the help

  13. #13

    Default Re: Suggestions for particular text format in QTextEdit

    Hi

    If someone is interested I found the solution. Basically I created tables with css style "float:left" that is supported by QTextEdit control. This will result to show tables in the same line and move on the next line if the edit control is resized, exactly what I need. Thank you to all for the support.

Similar Threads

  1. QTextEdit format html code
    By Edder in forum Qt Programming
    Replies: 1
    Last Post: 14th July 2012, 16:03
  2. can't get format under cursor of a QTextEdit
    By dvirtz in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2011, 13:12
  3. Problem with Qtextedit format - hex viewing
    By daro21 in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2011, 20:18
  4. Support for .rtf format in QTextDocument or QTextEdit?
    By LynneV in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2010, 00:01
  5. QTextEdit current cursor text format
    By afail in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 15:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.