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. Want to change selected text's font put I can't

Want to change selected text's font put I can't

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 4.6k 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.
  • A Offline
    A Offline
    amir734jj
    wrote on last edited by
    #1

    I am writing a text editor and I got a serious problem
    When I click on Bold , it Bolds everything not the selected text
    There is the same problem when I click on Italisize or small, normal, large

    Any idea would be appreciated

    Thanks

    http://s23.postimg.org/u7r6axgxn/Untitled.jpg

    Link to my code (sorry was longer than 6000 character so I couldn't paste it here)

    https://www.dropbox.com/sh/g2hq0dmk9768ps5/v_3kUsxdQl

    Please check

    createBoldAndItalic();
    createSizeChange();

    1 Reply Last reply
    0
    • P Offline
      P Offline
      przemub
      wrote on last edited by
      #2

      Hello, ~amir734jj

      I looked into your source code and it's not cool.

      Your problem lies in setBold() of mainwindow.cpp:129
      @
      textEdit->setFont(newFont);
      @

      You are sayin' that it doesn't apply changes for selected text, but it shouldn't. It sets style for the whole text!

      I would advice you to find another workaround here, ok?

      :D

      1 Reply Last reply
      0
      • A Offline
        A Offline
        amir734jj
        wrote on last edited by
        #3

        What do you mean by workaround ?

        Sorry I am not a native English speaker !

        1 Reply Last reply
        0
        • P Offline
          P Offline
          przemub
          wrote on last edited by
          #4

          C'mon, man! There is google for these things! http://en.wikipedia.org/wiki/Workaround

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            try this (not actively tried though):
            @
            QTextCursor cursor = textEdit->textCursor();
            QFont boldFont(textEdit->font());
            boldFont.setBold(true);
            QTextCharFormat format;
            format.setFont(boldFont);
            cursor.setBlockCharFormat(format);
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tucnak
              wrote on last edited by
              #6

              [quote author="raven-worx" date="1367475346"]try this (not actively tried though):
              @
              QTextCursor cursor = textEdit->textCursor();
              QFont boldFont(textEdit->font());
              boldFont.setBold(true);
              QTextCharFormat format;
              format.setFont(boldFont);
              cursor.setBlockCharFormat(format);
              @[/quote]

              It's not enough though :) Final code is going to be:
              @
              QTextCursor cursor = textEdit->textCursor();
              QFont boldFont(textEdit->font());
              boldFont.setBold(true);
              QTextCharFormat format;
              format.setFont(boldFont);
              cursor.setBlockCharFormat(format);
              textEdit->setCursor(cursor); // maybe &cursor :)
              @

              1 Reply Last reply
              0
              • A Offline
                A Offline
                amir734jj
                wrote on last edited by
                #7

                Getting this error

                D:\qt\CS_337_Final_Project\mainwindow.cpp:116: error: C2664: 'QWidget::setCursor' : cannot convert parameter 1 from 'QTextCursor *' to 'const QCursor &'
                Reason: cannot convert from 'QTextCursor *' to 'const QCursor'
                No constructor could take the source type, or constructor overload resolution was ambiguous

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tucnak
                  wrote on last edited by
                  #8

                  [quote author="amir734jj" date="1367547168"]Getting this error

                  D:\qt\CS_337_Final_Project\mainwindow.cpp:116: error: C2664: 'QWidget::setCursor' : cannot convert parameter 1 from 'QTextCursor *' to 'const QCursor &'
                  Reason: cannot convert from 'QTextCursor *' to 'const QCursor'
                  No constructor could take the source type, or constructor overload resolution was ambiguous[/quote]

                  Sorry, use this one instead: http://qt-project.org/doc/qt-4.8/qtextedit.html#setTextCursor

                  And why can't people not copy-paste but think, think a bit?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    amir734jj
                    wrote on last edited by
                    #9

                    Man !!

                    Today Is exactly the fourth day I am using qt for first time in my life !!!

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tucnak
                      wrote on last edited by
                      #10

                      [quote author="amir734jj" date="1367547460"]Man !!

                      Today Is exactly the fourth day I am using qt for first time in my life !!!

                      [/quote]

                      Man !!

                      Today Is exactly the 100th day I am hearing this words from people on devnet in my life !!!

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        amir734jj
                        wrote on last edited by
                        #11

                        Man ...

                        it wasn't a joke.I am just a sophomore in CS (18.5 years old !!! ) who knows only java and c/c++ !!!

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          tucnak
                          wrote on last edited by
                          #12

                          [quote author="amir734jj" date="1367547747"]Man ...

                          it wasn't a joke.I am just a sophomore in CS (18.5 years old !!! ) who knows only java and c/c++ !!!
                          [/quote]

                          Okay, guy. I know C++, don't know Java. I am 14 years old. I know how to use reference documentation.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            amir734jj
                            wrote on last edited by
                            #13

                            FYI ... it didn't work !

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              amir734jj
                              wrote on last edited by
                              #14

                              Ok , Thanks man

                              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