Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    14
    3833
    Loading More Posts
    • 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
      amir734jj last edited by

      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 Reply Quote 0
      • P
        przemub last edited by

        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 Reply Quote 0
        • A
          amir734jj last edited by

          What do you mean by workaround ?

          Sorry I am not a native English speaker !

          1 Reply Last reply Reply Quote 0
          • P
            przemub last edited by

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

            1 Reply Last reply Reply Quote 0
            • raven-worx
              raven-worx Moderators last edited by

              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 Reply Quote 0
              • T
                tucnak last edited by

                [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 Reply Quote 0
                • A
                  amir734jj last edited by

                  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 Reply Quote 0
                  • T
                    tucnak last edited by

                    [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 Reply Quote 0
                    • A
                      amir734jj last edited by

                      Man !!

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

                      1 Reply Last reply Reply Quote 0
                      • T
                        tucnak last edited by

                        [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 Reply Quote 0
                        • A
                          amir734jj last edited by

                          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 Reply Quote 0
                          • T
                            tucnak last edited by

                            [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 Reply Quote 0
                            • A
                              amir734jj last edited by

                              FYI ... it didn't work !

                              1 Reply Last reply Reply Quote 0
                              • A
                                amir734jj last edited by

                                Ok , Thanks man

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post