Results 1 to 13 of 13

Thread: Trouble with QGraphicsTextItem events

Hybrid 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

  2. #2
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble with QGraphicsTextItem events

    I am not sure..but i would have declared my QGraphicsItem in the header file instead of constructor ....

  3. #3
    Join Date
    Jul 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trouble with QGraphicsTextItem events

    There is nothing with it...

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble with QGraphicsTextItem events

    hmm..so only the event is not working or the whole screen is empty .!!

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

    Default Re: Trouble with QGraphicsTextItem events

    Only the event. QGraphicsTextItem creates. When I select it, dotted frame round QGraphicsTextItem is created, but nothing more happens.
    The same event with QPushButton works well.
    connect(button,SIGNAL(clicked()),this,SLOT(start() ));
    But I need just QGraphicsTextItem.

  6. #6
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Trouble with QGraphicsTextItem events

    Hi Flippik,

    I've done something similar with QGraphicsPixmapItem. The code is at

    http://chhobi.cvs.sourceforge.net/ch....h?view=markup

    The class is called ThumbnailItem.

    The file photo.cpp has the implementation.

    Perhaps that example will help.

    -K

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with QGraphicsTextItem events

    connect(stLabel3,SIGNAL(linkActivated(const QString&)),this,SLOT(start()));
    Dont you think SIGNAL and SLOT should have same signature ??

  8. #8
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble with QGraphicsTextItem events

    Dont you think SIGNAL and SLOT should have same signature ??
    correct me if i am wrong but slot can have shorter signature than signal...

  9. #9
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with QGraphicsTextItem events

    Hi ,
    is the signal realy emitted?
    void QGraphicsTextItem::linkActivated ( const QString & link ) [signal]
    This signal is emitted when the user clicks on a link on a text item that enables Qt::LinksAccessibleByMouse or Qt::LinksAccessibleByKeyboard. link is the link that was clicked.
    Maybe it s not emitted if you click on text that is not a link .
    Hope it helps.

  10. #10
    Join Date
    Jul 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trouble with QGraphicsTextItem events

    How can I check if the signal is emitted?
    I've tried to do it as a link(stLabel3->setHtml("<a href=http://www.ya.ru>hello!!!</a>")),but nothing has changed..I've read the Assistant help for QGraphicsTextItem class reference and found only two signals that could be generated(linkActivated, linkHovered). Is it really to do this way or my efforts are useless?
    kghose: I've not found anything useful for me...
    Last edited by Flippik; 31st July 2008 at 07:33.

  11. #11
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with QGraphicsTextItem events

    If the reference says that linkActivated is emitted when......that means that by default it s emitted when some event occurs ......
    Ok ,I am doing my own test.... linkHovered is emited if you set Html to the item (I did :
    Qt Code:
    1. setHtml("<A href=../imagenes/bosque.gif>mapa del bosque encantado.</A>");
    To copy to clipboard, switch view to plain text mode 

    )
    With plain text or html without links ,nothing happens.
    Same thing with linkActivated .
    Could it be that your slot is private?Also make sure the names of signals and slots are ok .
    Hope you fix it.

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.