Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPlainTextEdit in a QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

QPlainTextEdit in a QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 513 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wejgomi
    wrote on 6 Jan 2019, 23:40 last edited by
    #1

    Hi,

    I am trying to embed a movable code editor into a QGraphicsView.

    Currently I am able to embed a QPlainTextEdit into a QGraphicsView. I use QGraphicsProxyWidget and also set QPlainTextEdit `s parent as another QGraphicsWidget item.

       QGraphicsWidget* parentWidget = new QGraphicsWidget();
      parentWidget->setMinimumSize(QSizeF(100, 30));
      parentWidget->setFlags(QGraphicsItem::ItemIsMovable);
      parentWidget->setAutoFillBackground(true);
      scene->addItem(parentWidget);
    
     editor = new QPlainTextEdit(); 
     QGraphicsProxyWidget *proxy = scene->addWidget( editor);
     proxy->setParentItem(parentWidget);
     proxy->setWidget(editor);
     proxy->setPos(5, 5);
     proxy->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemSendsGeometryChanges |
                            QGraphicsItem::ItemSendsScenePositionChanges);
    

    This helps me to render the QPlainTextEdit object in QGraphicsView. It also receives mouse events and it is movable since its QGraphicsWidget parent is movable.

    The problem is QPlainTextEdit object does not receive keyboard events. How can I achieve this by using this setup ?

    If I can not , which one would be the better alternative ?

    a) Implementing a code editor from QGraphicsTextItem
    b) Rendering QPlainTextEdit on top of QGraphicsWidget and making it movable

    Thanks in advance

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 Jan 2019, 22:46 last edited by
      #2

      Hi,

      Looks like you are missing the QGraphicsItem::ItemIsFocusable flag.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • W Offline
        W Offline
        wejgomi
        wrote on 8 Jan 2019, 08:47 last edited by
        #3

        Thank you very much , it worked !

        1 Reply Last reply
        0

        2/3

        7 Jan 2019, 22:46

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved