Results 1 to 5 of 5

Thread: Text interaction with QGraphicsTextItem in multiple scenes and views

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 

Similar Threads

  1. Scene vs. multiple views
    By lni in forum Qt Programming
    Replies: 16
    Last Post: 19th July 2022, 01:47
  2. Multiple Views One GL Context
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2010, 22:23
  3. QGraphicsTextItem bug on mouse interaction?
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2008, 07:29
  4. entering text through user interaction in QTextEdit
    By sar_van81 in forum Qt Programming
    Replies: 6
    Last Post: 1st December 2006, 22:41
  5. adding QGraphicsItem to multiple scenes
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2006, 14: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
  •  
Qt is a trademark of The Qt Company.