Qt World Summit: Register Today!

[SOLVED!] Build a single widget from source

  • Hi there,

    While thinking about my question as original posted, I concluded that the question could be asked a lot simpler. So here it is.

    I am trying to build QTextEdit from source. I have taken the source files including private headers, renamed them (removed the Q at the beginning) and tried to build it as is, but so far no luck. For every change I make, various new problems pop up.

    Is it possible to build just a single widget from source (in my case QTextEdit)?

  • Lifetime Qt Champion


    It really depends on the widget and QTextEdit is not the most simple to take apart.

    In what way do you want to extend it ?

  • I want to make som changes in the QTextHtmlParser class, which is a private class of QTextDocument. And offcourse the result should be visible/editable in (a custom) QTextEdit.

    I figured that changing QTextDocument would also affect QTextEdit.

  • Lifetime Qt Champion

    Then rather keep the discussion on only one thread since this one will duplicate that "one":http://qt-project.org/forums/viewthread/53180/

  • Just closed that one.

  • Yesterday I decided to make a new start with QTextDocument, hence the "other":http://qt-project.org/forums/viewthread/53180/ topic. Taking the source files of QTextDocument and adding all other as needed. Renaming (removing the Q) the classes turned out to be a lot of work.

    Now I am facing the following error:
    @'QExplicitlySharedDataPointer<QFontPrivate> QFont::d' is private
    QExplicitlySharedDataPointer<QFontPrivate> d;

    Changing the QFont class doens't seem smart to do, because the further I go the less I can make use of the standard stuff.

    Any advice on where to go from here?

  • For now I have taken a slight different apporach, since everything I have done so far just ends with not being able to use QFont etc.

    From what I have learned so far, the way QTextDocument translates html into somting readable, I am able to create a different parser and add it to an subclass of QTextDocument.

    Since SGaist has said that QTextedit is not the easiest to take apart, should I better write an new editor? Painting the contents of a QTextDocument on an widget is something I have done before. But how to make it editable? Reading trough all the code has been a bit overwhelming.

    Perhaps some insight on that?

  • Lifetime Qt Champion

    Did you try to just "Clone" QTextDocument and just modify its name and the one from the private implementation but leave the rest Qt ?

  • Thats how I started. I changed the name of the file (qtextdocument.h to textdocument.h etc.) and of the class, QTextDocument and QTextDocumentPrivate to TextDocument and TextDoxumentPrivate.

    But then I ran in trouble, because QTextBlock, QTextCursor and so on expect a QTextDocument and not a TextDocument. So I started working on them too.

    Perhaps that was a bit to enthousiastic.

  • I gave it another try, but I stumble upon the same problem. When I created a demoproject with the htmlparser (see earlier post), I was able to exclude the private headers from other classes in the html parser without any big problems.

    This approach doesn't work with QTextDocument, since QTextDocumentPrivate is also used in QTextCursor and QTextObject. And QTextDocument is used in a lot more classes.

    I have tried it with a static_cast which did not work. Besides, since the private headers are not part of the Qt API, this would not be an everlasting solution I think.

  • Lifetime Qt Champion

    Looks like you would have less problems modifying Qt for your purpose...

  • If you mean by modifying subclassing and adding functionality, then you are absolutely right. But it isn't only about functionality, but also about performance.
    When I can build an editor with a custom document, I can also tailor it to fit it's primary task and thus making it more efficiƫnt. For example like QCodeEditor.

  • Well, although I am far from finished, I seem to have found the trick.

    As sugested by SGaist I have "cloned" QTextDocument and the one from the private implementation.

    I have added core-private and gui-private to the .pro file for the time being. These will be deleted if all is finished.
    Next I have copied QTextHtmlParser and added is to the project as a class and created a HtmlImporter class after which the private header of QtextDocumentFragment can be excluded.

    This is working, so now to the next private headers...

    I guess this makes this thread solved.

    Thank you SGaist for your suggestions.

Log in to reply