Results 1 to 3 of 3

Thread: Editable content in Webkit

  1. #1
    Join Date
    Apr 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Editable content in Webkit

    Hi there,

    I'm building a rudimentary WYSIWYG/code editor widget based on Webkit
    and the contenteditable attribute, and I'm finding it quite
    straightforward so far. However, there's one issue I can't figure out.
    To toggle bold text (for example), it's sufficient to do this:

    webView->triggerPageAction(QWebPage::ToggleBold);

    However, I would also like to be able to make my menu items and toolbar
    buttons reflect the state of the text under the cursor, so that (for
    instance) if the cursor is on bold text, the Bold toolbar button would
    be pressed and the menu item would be checked. This is clearly possible,
    because the default context menu provided the webkit instance works this
    way, but I can't find out how to read the state of the current text from
    the control.

    I found this example project:

    http://labs.qt.nokia.com/2009/03/12/...g-html-editor/

    which looks like it might show me what I need, but the codebase is no
    longer available; it was in the Trolltech git repository, which is no
    longer there, and I can't find it in the qt-project.org git repo.

    Can anyone suggest a solution to this, or, failing that, show me where I
    might find the wysiwyg-html-editor project?

    All help appreciated,
    Martin

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Editable content in Webkit

    Use QWebView::pageAction() to get a pointer to the QAction object associated with the action you want. Then add this action to your toolbar or menu. If you want to manually associate it with a tool button that is not in the toolbar, call setDefaultAction() on it, passing it the action received from QWebView.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Editable content in Webkit

    Quote Originally Posted by wysota View Post
    Use QWebView::pageAction() to get a pointer to the QAction object associated with the action you want. Then add this action to your toolbar or menu. If you want to manually associate it with a tool button that is not in the toolbar, call setDefaultAction() on it, passing it the action received from QWebView.
    I'll give that a try. I have a slight complication in that I'm going to be using several of these widgets in one GUI, so I'll need to keep changing the action associated with each menu item or toolbutton each time the focus changes from one webkit widget to another.

    Another approach I've tried is to use QWebView:ageAction() to get a pointer to the action, and then read the checked property of the action, but that doesn't seem to work, unfortunately; the bold action comes back unchecked even when the cursor is on bold text.

    Thanks,
    Martin

Similar Threads

  1. Replies: 4
    Last Post: 23rd September 2010, 15:20
  2. modifying webkit content before loads
    By rbp in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2010, 06:00
  3. QGraphicsTextItem is not editable
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 29th September 2009, 15:51
  4. Editable QTreeView
    By winston2020 in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 13:18
  5. how to set up a QHeaderView editable?
    By iguanna in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2008, 14:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.