July 15, 2012

Pablik2005 Pablik2005
Lab Rat
33 posts

QPlaintTextEdit and setFont to selected Char

 

Hi, how can setFont() to selected char in QPlainTextEdit (no to all QPlainTextEdit) ???

9 replies

July 15, 2012

abbas farahmand abbas farahmand
Robot Herder
373 posts

are you test it ?

  1. setCurrentCharFormat()

 Signature 

If You Want You Can!

July 15, 2012

Pablik2005 Pablik2005
Lab Rat
33 posts

setCurrentCharFormat () it’s work thx ;)
i have next question, if i want save all text inside QPlainTextEdit to file and load this text(with this font), then i have make big array of QTextCharFormat and save this TextCharFormat for each char in QPlainTextEdit, or is better way ??

July 15, 2012

abbas farahmand abbas farahmand
Robot Herder
373 posts

you are welcome.
no,if you save this text with current font,and read it and set it as plain text , it works without any problem with your formats.

 Signature 

If You Want You Can!

July 15, 2012

Pablik2005 Pablik2005
Lab Rat
33 posts

But how save with current font ??
Before i do that:
Save-
QTextStream < QPlainTextEdit->toPlainText();
Load-
QPlainTextEdit->setPlainText(QTextStream.readAll());

July 15, 2012

abbas farahmand abbas farahmand
Robot Herder
373 posts

this is works,

  1. //for save :
  2. ui->plainTextEdit->toPlainText();
  3. //this is save the texts with formats.

 Signature 

If You Want You Can!

July 15, 2012

Pablik2005 Pablik2005
Lab Rat
33 posts

it’s didnt work ;(

Save

  1. void PageItem::save()
  2. {
  3.  
  4.     if( haveFile )
  5.     {
  6.         if( !isSaved )
  7.         {
  8.             if( File->open(QIODevice::WriteOnly | QIODevice::Text ))
  9.             {
  10.                 QTextStream t_Stream(File);
  11.                 t_Stream << PlainTextEdit->toPlainText();
  12.  
  13.                 File->close();
  14.             }
  15.  
  16.             isSaved = true;
  17.  
  18.         }
  19.     }else
  20.     {
  21.         QFileDialog t_Dialog(0);
  22.         saveAs(t_Dialog.getSaveFileName(0,"Save"));
  23.     }
  24. }

Open

  1.     if(File->open(QIODevice::ReadOnly | QIODevice::Text))
  2.     {
  3.         QTextStream stream(File);
  4.  
  5.         PlainTextEdit->setPlainText(stream.readAll());
  6.         File->close();
  7.     }

if i save with font after open font is default (not like after save)

July 16, 2012

abbas farahmand abbas farahmand
Robot Herder
373 posts

Pablik2005 , I thi* nk you want to save your QPlainTextEdit content with format to rtf file!
but,rtf files and it’s formats just for Microsoft ;Not Standard For All Platforms!

if you want to save your custom text format, you can save it and open it by HTML tags.
Convert it to HTML or use QTextEdit as this :

  1. //for open
  2. ui->textEdit->setHtml("<b>Bold Text</b>");
  3.  
  4. //for save
  5. ui->textEdit->toHtml();

 Signature 

If You Want You Can!

July 16, 2012

abbas farahmand abbas farahmand
Robot Herder
373 posts

and if you want to design a text editor , see this link [qt-apps.org]

 Signature 

If You Want You Can!

July 16, 2012

Pablik2005 Pablik2005
Lab Rat
33 posts

ok thx for help

 
  ‹‹ can’t execute all query!      How to submit patch to Qt5 development tree ››

You must log in to post a reply. Not a member yet? Register here!