Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OpenUrl from a QGraphicsView [Solved]
QtWS25 Last Chance

OpenUrl from a QGraphicsView [Solved]

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k Views
  • 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 Offline
    J Offline
    justdad
    wrote on last edited by
    #1

    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
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on last edited by
      #2

      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
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        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
        0
        • J Offline
          J Offline
          justdad
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved