Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    OpenUrl from a QGraphicsView [Solved]

    General and Desktop
    3
    4
    2665
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      justdad last edited by

      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;

      imageLoaded = pixmap.load(QString(":/new/prefix1/my_logo1.png"));
      
      QGraphicsScene *gs = new QGraphicsScene;
      QRect rect = ui->graphicsLogoView->geometry();
      gs->addPixmap(pixmap.scaledToWidth(rect.width()-10));
      
      
      ui->graphicsLogoView->setScene(gs);
      ui->graphicsLogoView->show();
      ui->graphicsLogoView->setStyleSheet("background: transparent");
      

      @

      1 Reply Last reply Reply Quote 0
      • R
        RazrFalcon last edited by

        You can use standard QPushButton for this. Add it in designer. And then:
        @pushButton->setStyleSheet("QPushButton {border: none; padding: 0px;}");
        pushButton->setIcon(QIcon(":/new/prefix1/my_logo1.png"));@

        Then, in designer, create slot clicked() for this button and in this slot write:
        @QDesktopServices::openUrl(QUrl("www.cnn.com", QUrl::TolerantMode));@

        PS: you also need to add:
        @#include <QDesktopServices>@

        1 Reply Last reply Reply Quote 0
        • Z
          ZapB last edited by

          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().

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply Reply Quote 0
          • J
            justdad last edited by

            Thanks, I switched to using a button and worked fine. Thanks.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post