Want to change selected text's font put I can't
-
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, largeAny 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(); -
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
-
C'mon, man! There is google for these things! http://en.wikipedia.org/wiki/Workaround
-
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 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 :)
@ -
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 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?
-
[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.