[Qt-interest] QDataWidgetMapper and Custom Widget
NaGeL
nagel182 at gmail.com
Sun May 1 14:53:48 CEST 2011
thank you very much! I will try this out.
2011/5/1 Robert Escott <robert at binarylogic.co.za>
> You most likely have functions that can read and set the value of custom
> widget with the value from the data model. If the type is QString, then
> it'll probably look something like this:
> *
> class CustomWidget : public QWidget{
> public:
> //....
> QString value() const;
> void setValue(QString const &);
> // ...
> };*
>
> You would probably already have the following connections made for the
> QDataWidgetMapper:
> *
> QDataWidgetMapper mapper;
> mapper.setModel(myModel);
> mapper.addMapping(myWidget, 1); // Where 1 is the column in your model that
> contains the value for your custom widget*
>
> If you have this kind of connection, the QDataWidgetMapper will be looking
> through the QMetaProperty list for properties that have the USER flag set
> and then updating that property with the data model's value. To create this
> property, you give it a type, a name, list it's accessor methods and then
> mark it as a user-facing property.
>
> *class CustomWidget : public QWidget{
> Q_OBJECT
> Q_PROPERTY(QString value READ value WRITE setValue USER true)
> public:
> //....
> QString value() const;
> void setValue(QString const &);
> // ...
> };*
>
> If you wish to map a property that is not a USER property, you use the
> alternative mapping function that names the property.
>
> *mapper.addMapping(myWidget, 1, "value");*
>
> Read up on "The Property System" in the documentation if you want more
> information.
>
>
> On 01/05/2011 12:18, NaGeL wrote:
>
> thank you for the answer, and i read Q_property... but i dont quite
> understand it how it works...or more like i don't really understand whats
> its use, pourpuse.
>
> Could you explain it to me?
>
> 2011/4/30 Robert Escott <robert at binarylogic.co.za>
>
>> Have a look in the documentation about Q_PROPERTY
>>
>> If I remember correctly, QDataWidgetMapper will try and use the data it
>> gets from the model and set it to whatever property is set as the USER
>> property.
>>
>>
>> On 30/04/2011 00:24, NaGeL wrote:
>>
>> Hello? would somebody nice enough to reply me that this has been asked
>> already, or its a dumb question because Qt does this automatically, or no
>> one did understand me?
>>
>> 2011/4/28 NaGeL <nagel182 at gmail.com>
>>
>>> Hello!
>>> Newbie here.Also English isn't my native language, so sorry for any
>>> hiccups.
>>>
>>> I'm currently doing a program that loads data from an SQL database,
>>> present it to the user, an d the user have the option to edit it...
>>>
>>> never mind that. I used QDatawidgetmapper to map simple QLineEdits, and
>>> a Qcheckbox.
>>> This is all good, but there is a text field which requires a bigger field
>>> of text and needs to be presented to the user styled.(bold, italic crossed
>>> text etc.)
>>>
>>> I figured I make a Custom Widget with QTextEdit and a toolbar that makes
>>> the styles, like a bold button, etc.
>>> and put the Custom Widget into the editor.
>>>
>>> My question is: How can I use QDataWidgetMapper to map my custom Widget,
>>> and in that QTextEdit?
>>>
>>> Also I would ask that QTextEdit uses Html tags as style right? Is there
>>> a way to change that? using custom tags to style the text? I want to use
>>> something database lighter.
>>>
>>> Again sorry if this sounds gibberish, English isn't my firts language, if
>>> this not understandable i will try to explain the whole situation in my next
>>> post.
>>>
>>
>>
>> _______________________________________________
>> Qt-interest mailing listQt-interest at qt.nokia.comhttp://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>
>>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110501/e9a2a03d/attachment.html
More information about the Qt-interest-old
mailing list