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. QTextCharFormat setfont not working
Qt 6.11 is out! See what's new in the release blog

QTextCharFormat setfont not working

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 643 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
     // [ Text 폰트 사이즈 변경 ]
        QFont f("Arial", 140, QFont::Bold);
        QTextCharFormat format = cursor.charFormat();
        format.setFont(f);
        //format.setFontPointSize(140);
        //cursor.setCharFormat(format);
        cursor.mergeCharFormat(format);
    

    Can you look at my code? The font attribute is not applied, so I want to change the text size or font.

    eyllanescE 1 Reply Last reply
    0
    • I IknowQT
      QTextCursor cursor(this->ui.textEdit->textCursor());
      cursor.movePosition(QTextCursor::Start);
         
          // 프레임 생성 
      	
      	QTextFrame* topFrame = cursor.currentFrame();
      	QTextFrameFormat topFrameFormat = topFrame->frameFormat();
      	topFrameFormat.setPadding(16);                                  // 전체 Padding 여백
      	topFrame->setFrameFormat(topFrameFormat);
      	
          QFont f("Bahnschrift SemiBold", 30);
      	QTextCharFormat textFormat;
          textFormat.setFont(f);
      
          QTextFrameFormat referenceFrameFormat;
          referenceFrameFormat.setBorder(1);
          referenceFrameFormat.setPadding(8);
          referenceFrameFormat.setPosition(QTextFrameFormat::InFlow);
          referenceFrameFormat.setWidth(QTextLength(QTextLength::VariableLength, 40));
          cursor.insertFrame(referenceFrameFormat);
      
      
      	// [ 제목 표시줄 생성 ]
      	{
              // [ Text 가운데 정렬 코드 ]		
              QTextBlockFormat textBlockFormat = cursor.blockFormat();
              textBlockFormat.setAlignment(Qt::AlignCenter);
      		cursor.mergeBlockFormat(textBlockFormat);
      
      		cursor.insertText("Measure Summary", textFormat);
      		cursor.setPosition(topFrame->lastPosition());
      	}
      
          // [ 측정 정보 란 생성 ]
          {
              QTextBlockFormat textBlockFormat1 = cursor.blockFormat();
              textBlockFormat1.setAlignment(Qt::AlignCenter);
              cursor.mergeBlockFormat(textBlockFormat1);
      
              textFormat.setFontPointSize(15);       
              referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);
              referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 25));
              
              cursor.insertFrame(referenceFrameFormat);
              cursor.insertText("Measure Info", textFormat);
              cursor.insertBlock();
      
              textFormat.setFontPointSize(10);
              cursor.insertText("Report Time\t[data]", textFormat);
              cursor.insertBlock();
              cursor.insertText("Operator\t[data]", textFormat);
              cursor.insertBlock();
              cursor.insertText("Instrument\t[data]", textFormat);
              cursor.insertBlock();
              cursor.insertText("Version\t[data]", textFormat);
              cursor.insertBlock();
              cursor.insertText("Temperature\t[data]", textFormat);
          }
      
      QTextBlockFormat textBlockFormat1 = cursor.blockFormat();
              textBlockFormat1.setAlignment(Qt::AlignCenter);
              cursor.mergeBlockFormat(textBlockFormat1);
      

      The 2nd QTextBlockFormat's text can't be aligned either.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #4

      @IknowQT try with: ui.textEdit->setTextCursor(cursor);

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      I 1 Reply Last reply
      0
      • I IknowQT
         // [ Text 폰트 사이즈 변경 ]
            QFont f("Arial", 140, QFont::Bold);
            QTextCharFormat format = cursor.charFormat();
            format.setFont(f);
            //format.setFontPointSize(140);
            //cursor.setCharFormat(format);
            cursor.mergeCharFormat(format);
        

        Can you look at my code? The font attribute is not applied, so I want to change the text size or font.

        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #2

        @IknowQT what is cursor? please provide a minimal and compilable example.

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          IknowQT
          wrote on last edited by
          #3
          QTextCursor cursor(this->ui.textEdit->textCursor());
          cursor.movePosition(QTextCursor::Start);
             
              // 프레임 생성 
          	
          	QTextFrame* topFrame = cursor.currentFrame();
          	QTextFrameFormat topFrameFormat = topFrame->frameFormat();
          	topFrameFormat.setPadding(16);                                  // 전체 Padding 여백
          	topFrame->setFrameFormat(topFrameFormat);
          	
              QFont f("Bahnschrift SemiBold", 30);
          	QTextCharFormat textFormat;
              textFormat.setFont(f);
          
              QTextFrameFormat referenceFrameFormat;
              referenceFrameFormat.setBorder(1);
              referenceFrameFormat.setPadding(8);
              referenceFrameFormat.setPosition(QTextFrameFormat::InFlow);
              referenceFrameFormat.setWidth(QTextLength(QTextLength::VariableLength, 40));
              cursor.insertFrame(referenceFrameFormat);
          
          
          	// [ 제목 표시줄 생성 ]
          	{
                  // [ Text 가운데 정렬 코드 ]		
                  QTextBlockFormat textBlockFormat = cursor.blockFormat();
                  textBlockFormat.setAlignment(Qt::AlignCenter);
          		cursor.mergeBlockFormat(textBlockFormat);
          
          		cursor.insertText("Measure Summary", textFormat);
          		cursor.setPosition(topFrame->lastPosition());
          	}
          
              // [ 측정 정보 란 생성 ]
              {
                  QTextBlockFormat textBlockFormat1 = cursor.blockFormat();
                  textBlockFormat1.setAlignment(Qt::AlignCenter);
                  cursor.mergeBlockFormat(textBlockFormat1);
          
                  textFormat.setFontPointSize(15);       
                  referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);
                  referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 25));
                  
                  cursor.insertFrame(referenceFrameFormat);
                  cursor.insertText("Measure Info", textFormat);
                  cursor.insertBlock();
          
                  textFormat.setFontPointSize(10);
                  cursor.insertText("Report Time\t[data]", textFormat);
                  cursor.insertBlock();
                  cursor.insertText("Operator\t[data]", textFormat);
                  cursor.insertBlock();
                  cursor.insertText("Instrument\t[data]", textFormat);
                  cursor.insertBlock();
                  cursor.insertText("Version\t[data]", textFormat);
                  cursor.insertBlock();
                  cursor.insertText("Temperature\t[data]", textFormat);
              }
          
          QTextBlockFormat textBlockFormat1 = cursor.blockFormat();
                  textBlockFormat1.setAlignment(Qt::AlignCenter);
                  cursor.mergeBlockFormat(textBlockFormat1);
          

          The 2nd QTextBlockFormat's text can't be aligned either.

          eyllanescE 1 Reply Last reply
          0
          • I IknowQT
            QTextCursor cursor(this->ui.textEdit->textCursor());
            cursor.movePosition(QTextCursor::Start);
               
                // 프레임 생성 
            	
            	QTextFrame* topFrame = cursor.currentFrame();
            	QTextFrameFormat topFrameFormat = topFrame->frameFormat();
            	topFrameFormat.setPadding(16);                                  // 전체 Padding 여백
            	topFrame->setFrameFormat(topFrameFormat);
            	
                QFont f("Bahnschrift SemiBold", 30);
            	QTextCharFormat textFormat;
                textFormat.setFont(f);
            
                QTextFrameFormat referenceFrameFormat;
                referenceFrameFormat.setBorder(1);
                referenceFrameFormat.setPadding(8);
                referenceFrameFormat.setPosition(QTextFrameFormat::InFlow);
                referenceFrameFormat.setWidth(QTextLength(QTextLength::VariableLength, 40));
                cursor.insertFrame(referenceFrameFormat);
            
            
            	// [ 제목 표시줄 생성 ]
            	{
                    // [ Text 가운데 정렬 코드 ]		
                    QTextBlockFormat textBlockFormat = cursor.blockFormat();
                    textBlockFormat.setAlignment(Qt::AlignCenter);
            		cursor.mergeBlockFormat(textBlockFormat);
            
            		cursor.insertText("Measure Summary", textFormat);
            		cursor.setPosition(topFrame->lastPosition());
            	}
            
                // [ 측정 정보 란 생성 ]
                {
                    QTextBlockFormat textBlockFormat1 = cursor.blockFormat();
                    textBlockFormat1.setAlignment(Qt::AlignCenter);
                    cursor.mergeBlockFormat(textBlockFormat1);
            
                    textFormat.setFontPointSize(15);       
                    referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);
                    referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 25));
                    
                    cursor.insertFrame(referenceFrameFormat);
                    cursor.insertText("Measure Info", textFormat);
                    cursor.insertBlock();
            
                    textFormat.setFontPointSize(10);
                    cursor.insertText("Report Time\t[data]", textFormat);
                    cursor.insertBlock();
                    cursor.insertText("Operator\t[data]", textFormat);
                    cursor.insertBlock();
                    cursor.insertText("Instrument\t[data]", textFormat);
                    cursor.insertBlock();
                    cursor.insertText("Version\t[data]", textFormat);
                    cursor.insertBlock();
                    cursor.insertText("Temperature\t[data]", textFormat);
                }
            
            QTextBlockFormat textBlockFormat1 = cursor.blockFormat();
                    textBlockFormat1.setAlignment(Qt::AlignCenter);
                    cursor.mergeBlockFormat(textBlockFormat1);
            

            The 2nd QTextBlockFormat's text can't be aligned either.

            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by
            #4

            @IknowQT try with: ui.textEdit->setTextCursor(cursor);

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            I 1 Reply Last reply
            0
            • eyllanescE eyllanesc

              @IknowQT try with: ui.textEdit->setTextCursor(cursor);

              I Offline
              I Offline
              IknowQT
              wrote on last edited by IknowQT
              #5

              @eyllanesc

              https://forum.qt.io/topic/130298/qtextimageformat-widget-grab-not-working

              Can you look at the content?

              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