Results 1 to 13 of 13

Thread: Trouble with QGraphicsTextItem events

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Trouble with QGraphicsTextItem events

    Hi2all! I need to work some event when user clicks or gets mouse over the QGraphicsTextItem. I'm trying to do it this way,but nothing happens/events do not work.
    Qt Code:
    1. // myScene.h
    2. #include <QSound>
    3. #include <QGraphicsScene>
    4.  
    5. class myScene : public QGraphicsScene
    6. {
    7. Q_OBJECT
    8. public:
    9. móScene(QObject *parent = 0);
    10. QSound *menuSound,*cSound;
    11.  
    12. private slots:
    13. void start();
    14. };
    15. //myScene.cpp
    16. myScene::myScene(QObject *parent) : QGraphicsScene(parent)
    17. {
    18. setBackgroundBrush(QPixmap(":/data/bg.png"));
    19. QGraphicsTextItem* stLabel3 = addText(trUtf8("smth"));
    20. //stLabel3->setHtml(trUtf8("smth"));
    21. stLabel3->setFlag(QGraphicsItem::ItemIsMovable);
    22. stLabel3->setPos(275,260);
    23. stLabel3->setDefaultTextColor(QColor(0,43,0,127));
    24. stLabel3->setFont(QFont("Comic Sans MS", 24, QFont::Bold,QFont::StyleItalic));
    25. stLabel3->adjustSize();
    26. stLabel3->setZValue(1);
    27. QTransform transform = stLabel3->transform();
    28. transform.rotate(80.0, Qt::YAxis);
    29. transform.scale(2., 1.5);
    30. stLabel3->setTransform(transform);
    31. stLabel3->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
    32. connect(stLabel3,SIGNAL(linkActivated(const QString&)),this,SLOT(start()));
    33.  
    34.  
    35. menuSound = new QSound("data/sound/menu.wav");
    36. cSound = new QSound("data/sound/mus_w1.wav");
    37. menuSound->play();
    38. }
    39.  
    40.  
    41. void myScene::start()
    42. {
    43. menuSound->stop();
    44. cSound->play();
    45. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 31st July 2008 at 21:23. Reason: missing [code] tags

Similar Threads

  1. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03

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.