OpenUrl from a QGraphicsView [Solved]
I have used Creater to create a QGraphicsView where I place my Logo. What I want to do is to have the web browser opened and the url “www.cnn.com” opened when the user clocks on this logo. Below is the code I use to load the Logo image from disk to the QGraphicsView. From research it looks like I need to override the mouseUp event or something like that but I am having problems trying to figure out how to over ride this when I have created the QGraphicsView in creator.
- QPixmap pixmap;
- gs->addPixmap(pixmap.scaledToWidth(rect.width()-10));
- ui->graphicsLogoView->setScene(gs);
- ui->graphicsLogoView->show();
- ui->graphicsLogoView->setStyleSheet("background: transparent");
3 replies
To do this in QGraphicsView you can subclass QGraphicsObject and QGraphicsPixmapItem and declare a clicked() signal.
Override the mousePressEvent() and check to see if it was the left mouse button which was pressed. If so emit your clicked signal.
Then in your mainwindow or somewhere else convenient connect to your custom item’s clicked() signal to a slot and from there call QDesktopServices::openUrl().
You must log in to post a reply. Not a member yet? Register here!


