PDA

View Full Version : Changing the Text Pattern?



ashukla
27th December 2007, 12:17
Dear All!
I am using the following code for changing the Text Pattern;


QPalette palette;
QBrush brush(fg);
QBrush brush1(fg);
brush.setStyle(Qt::HorPattern);
palette.setBrush(QPalette::Active, QPalette::Text, brush);
palette.setBrush(QPalette::Inactive, QPalette::Text, brush1);
QBrush brush2(bg);
brush2.setStyle(Qt::SolidPattern);
palette.setBrush(QPalette::Active, QPalette::Base, brush2);
textEdit->setPalette(palette);
but it is not change its Text Pattern Horizontal. However, I applied this upon Background of the QTextEdit, It applies.

How to get the Horizontal patterns in Text of QTextEdit.

wysota
27th December 2007, 13:19
I think the text is not drawn using the widget's brush. You might try changing the text block's format options instead.

ashukla
28th December 2007, 06:14
I think the text is not drawn using the widget's brush. You might try changing the text block's format options instead.
Dear Sir!
Please give me any example or link of this?

jpn
28th December 2007, 06:43
See for example QTextEdit::setCurrentCharFormat().

ashukla
28th December 2007, 07:07
See for example QTextEdit::setCurrentCharFormat().

Dear Sir!
I want the result as on attached Screen Shots.
The above is not suitable for me.
What should I do for this?

wysota
28th December 2007, 10:26
What did you already try?

ashukla
28th December 2007, 10:38
What did you already try?
Dear Sir!
As you said earlier I have searched many classes for that but I am unanble to found any useful function for this.
Mr. JPN has said use

See for example QTextEdit::setCurrentCharFormat().
__________________
Merry Christmas -- J-P Nurmi
but It's not usful in this case.
Please give me any suggestion in right direction to acheive the goal.

wysota
28th December 2007, 11:06
Have you written any code to test any of the given ideas?

ashukla
28th December 2007, 11:19
Have you written any code to test any of the given ideas?
Dear Sir!
No, b/z I have not gotten any function for that.

wysota
28th December 2007, 11:40
If not, then how come you say the given answers are useless if you didn't even bother to try them out? Have you acceessed the document of the text edit? Have you accessed the text block you want to change? Did you have a look at available options for the block of text?

ashukla
28th December 2007, 12:15
If not, then how come you say the given answers are useless if you didn't even bother to try them out? Have you acceessed the document of the text edit? Have you accessed the text block you want to change? Did you have a look at available options for the block of text?
Dear Sir!
I depicted carefully above ideas.
void QTextEdit::setCurrentCharFormat ( const QTextCharFormat & format )
It takes a arguments of QTextCharFormat object.
That only provides the following features;

void setAnchorNames ( const QStringList & names )
void setFont ( const QFont & font )
void setFontFamily ( const QString & family )
void setFontFixedPitch ( bool fixedPitch )
void setFontItalic ( bool italic )
void setFontOverline ( bool overline )
void setFontPointSize ( qreal size )
void setFontStrikeOut ( bool strikeOut )
void setFontUnderline ( bool underline )
void setFontWeight ( int weight )
void setTextOutline ( const QPen & pen )
void setToolTip ( const QString & text )
void setUnderlineColor ( const QColor & color )
void setUnderlineStyle ( UnderlineStyle style )
void setVerticalAlignment ( VerticalAlignment alignment )
QPen textOutline () const
QString toolTip () const
QColor underlineColor () const
UnderlineStyle underlineStyle () const
VerticalAlignment verticalAlignment () const

And the QTextBlock and QTextBlockFormat only provides the facility of indentation, pargraph settings etc.

So, that's the reason I have not wriiten any line of code for that b/z I am unable to find the right function until now.

So, If any function exists; please advice me for that.
Thanking you!

wysota
28th December 2007, 12:41
And what does QPen provide?

BTW. I was talking about the document, not the widget that display it.

jpn
28th December 2007, 12:44
It takes a arguments of QTextCharFormat object.
That only provides the following features;
Notice that QTextCharFormat is a QTextFormat.

ashukla
29th December 2007, 11:10
Dear JPN!
Thanks for your reply!
However It is working well for Qt::TexturePattern, Qt::DenseXPattern (here X means 1,2,3 ....7);
But I am not getting the horizontal pattern as I have attached the previous file.
So, What I change in my code;

QTextCharFormat format;
QBrush brush(Qt::blue,Qt::HorPattern);
format.setForeground(brush);
QTextCursor cursor = txtScrollEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::Document);
cursor.mergeCharFormat(format);
txtScrollEdit->setFontPointSize(28);
txtScrollEdit->setFontWeight(QFont::Bold);
txtScrollEdit->mergeCurrentCharFormat(format);
to get the desired output.

I am getting the output as attached in the sample.png. So, How a way I get output as I have attached earlier.