Results 1 to 5 of 5

Thread: Text interaction with QGraphicsTextItem in multiple scenes and views

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Text interaction with QGraphicsTextItem in multiple scenes and views

    I have multiple QGraphicsView items, each shown in a tab of an QTabWidget. Each view has its own QGraphicsScene.

    I have a problem with QGraphicsTextItem items in all views created after the first one. The problem is when I attempt to edit them - I have no text caret and the dashed border is also absent. However, I can still edit the item.

    I have reproduced the issue in the code below:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) :
    2. QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5. connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(newTab()));
    6. }
    7.  
    8. void MainWindow::newTab()
    9. {
    10. QGraphicsScene* scene = new QGraphicsScene(this);
    11.  
    12. QGraphicsTextItem* item = new QGraphicsTextItem("Hello World!");
    13. item->setTextInteractionFlags(Qt::TextEditorInteraction);
    14. scene->addItem(item);
    15.  
    16. QGraphicsView* view = new QGraphicsView(scene, ui.tabWidget);
    17. ui.tabWidget->addTab(view, "Scene");
    18. }
    To copy to clipboard, switch view to plain text mode 

    Interestingly, if I call newTab() multiple times inside the MainWindow's constructor, each view behaves as expected without the issue. However, all subsequent tabs suffer from text editing issue.

    Thanks in advance for any help anyone can give me. All files attached below.

    main.cpp
    MainWindow.ui
    MainWindow.h
    MainWindow.cpp

  2. #2
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text interaction with QGraphicsTextItem in multiple scenes and views

    According to QTabWidget's documentation you're not supposed to give a parent for widgets which you add as tabs to it.
    So, try this if it might help:
    Qt Code:
    1. QGraphicsView* view = new QGraphicsView(scene /*, ui.tabWidget*/ );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Text interaction with QGraphicsTextItem in multiple scenes and views

    Thanks joyer. Doesn't seem to fix the problem. I think it is the bug below:
    http://bugreports.qt.nokia.com/browse/QTBUG-18961

    Anybody have an idea how I can fix it as the software I am working on needs to be released soon?
    Last edited by joekemp; 3rd June 2011 at 10:17.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Text interaction with QGraphicsTextItem in multiple scenes and views

    Which Qt version are you using ? This bug seems to affect version 4.7.0, maybe you can just downgrade to 4.6.x ?

  5. #5
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Text interaction with QGraphicsTextItem in multiple scenes and views

    Hi stampede. I'm using version 4.7.1. I tried version 4.6.3 as you recommended, but the bug is still there.

Similar Threads

  1. Scene vs. multiple views
    By lni in forum Qt Programming
    Replies: 16
    Last Post: 19th July 2022, 02:47
  2. Multiple Views One GL Context
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2010, 23:23
  3. QGraphicsTextItem bug on mouse interaction?
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2008, 08:29
  4. entering text through user interaction in QTextEdit
    By sar_van81 in forum Qt Programming
    Replies: 6
    Last Post: 1st December 2006, 23:41
  5. adding QGraphicsItem to multiple scenes
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2006, 15:25

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.