Results 1 to 13 of 13

Thread: Trouble with QGraphicsTextItem events

  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.

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

    Default Re: Trouble with QGraphicsTextItem events

    Benne Gesserit: 10x u a lot. This trouble was 'cause my function was private, when i had changed it to public, everything was OK.
    And the next question: how can I get off a grey frame, that is created when I choose a QGraphicsTextItem?

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

    Default Re: Trouble with QGraphicsTextItem events

    My pleasure .I am very happy to help you .
    I have also been working with QGraphicsTextItem recently and found the same problem : I didnt like that grey frame .But it wasnt enough disturbing for me ,so I didnt spend time solving that .
    I dont know what s the best solution .And I am pretty sure this one I will post isnt the best solution,but you can try it.
    I guess somewhere you call QGraphicsTextItem:: paint() ,or you just leave it all to QGraphicsTextItem .What I did is reimplementing paint to "temporary disable somethings" :
    Qt Code:
    1. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    2. QWidget *widget){
    3. setFlag(QGraphicsItem::ItemIsSelectable , false);
    4. setFlag(QGraphicsItem::ItemIsFocusable , false);
    5. QGraphicsTextItem::paint(painter ,option ,widget);
    6. setFlag(QGraphicsItem::ItemIsSelectable , true);
    7. setFlag(QGraphicsItem::ItemIsFocusable , true);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    ,I find it very rude ,and I dont know if it can have collateral efects .Maybe not since it s just while the item is being painted.But I dont know .I was just triying to disable this in QGraphicsTextItem:: paint()
    Qt Code:
    1. if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))
    2. qt_graphicsItem_highlightSelected(this, painter, option);
    To copy to clipboard, switch view to plain text mode 

    I dont know how much this works.I tested it I little bit and I didnt see the the grey frame ,but maybe the interaction with the item fails .
    Hopefully someone else with more experience can give us (I want to know too)a better solution .
    Last edited by Benne Gesserit; 4th August 2008 at 23:36. Reason: change ::paint for :: paint
    If God has friends ,then I cant be God.

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.