PDA

View Full Version : QTextCharFormat question



moez
28th June 2010, 11:09
Hi,
This is a question for experimented qt scribe classes programmers.

I am trying to simulate check box widget inside my rich text.

so i have created a QTextObjectInterface that paint this 'check box' for me. I do store the 'check state' inside the a custom QTextChartFormat created for with this interface.


bool isChecked = false;
QTextCharFormat format = cursor.blockCharFormat();
format.setObjectType(CheckBoxTextFormat);
//CheckBox::CB_IsChecked
format.setProperty(CheckBox::CB_IsChecked,isChecke d);

When user click the 'checkbox' i do call this code to simulate a click


// QTextCursor cursor, QTextCharFormat format are in the right position where i have my QTextObject

bool isChecked = format.property(CheckBox::CB_IsChecked).toBool();
isChecked = !isChecked;
format.setProperty(CheckBox::CB_IsChecked,QVariant (isChecked));
cursor.beginEditBlock();
cursor.mergeCharFormat(format); //for some reason this don't work
cursor.cursor.setCharFormat(format); // also this don't work
// when painting the QTextObjectInterface read always the same value from format.property(CheckBox::CB_IsChecked).toBool();
// even if it was changed by above code.
cursor.endEditBlock();


Is this the proper manner to do such thing ?

Moez.

cyberduck
1st February 2012, 10:14
Hi,

that's very interesting for me. Heve you solved the problem?