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. My QGraphicsProxyWidget is not working, tested QWidget is
Qt 6.11 is out! See what's new in the release blog

My QGraphicsProxyWidget is not working, tested QWidget is

Scheduled Pinned Locked Moved General and Desktop
qgraphicsproxywqwidgetqgraphicsscenevideo
3 Posts 2 Posters 1.9k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #1

    Before removing comment when QGraphicsProxyWidget is created to view show(). this app is working.
    When this comment is removed & window assignment(setLayout, resize, show) commented, this app is no longer working( no longer showing 2 video side by side)
    Did i use QGraphicsProxyWidget correctly, i thought i did? Can someone comment on my error.

    @
    extern QStringList xmlID;
    extern QStringList xmlName;
    extern QStringList xmlValue;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    //
    QGraphicsScene scene;

    ml = new WidgetMarqueeLabel(this);
    ml->setDirection(1);
    ml->setSpeed(1);
    ml->setAlignment(Qt::AlignBottom);
    ml->setText(QString("%1").arg(xmlValue[2]));
    ml->setFont(QFont("Arial", 15,30));
    QGridLayout *layout= new QGridLayout;
    video();
    
    layout->addWidget(videoWidget,0,0);
    layout->addWidget(videoWidget1,0,1);
    layout->addWidget(ml,1,0,1,2);
    layout->setColumnStretch(0,10);
    layout->setColumnStretch(1,10);
    
    
    
    QWidget *window= new QWidget;
    window->setLayout(layout);
    

    // QGraphicsProxyWidget* proxy = scene.addWidget(window);

    // QGraphicsView view(&scene);
    // view.setWindowTitle("QWidget");
    // view.setFixedSize(800,900);
    // view.show();

       window->setLayout(layout);
       window->resize(1500,400);
       window->show();
    

    }

    //create new mediaplaylist, mediaplayer, Videowidget, playlist
    void MainWindow::video()
    {
    QString RealVideo1=xmlValue[0];
    playlist= new QMediaPlaylist();
    player= new QMediaPlayer;
    videoWidget = new QVideoWidget;
    playlist->addMedia(QUrl::fromLocalFile("/opt/night.mp4"));
    playlist->addMedia(QUrl::fromLocalFile("/opt/V7.mp4"));
    playlist->addMedia(QUrl::fromLocalFile("/opt/hotgirl.mp4"));
    playlist->addMedia(QUrl::fromLocalFile("/opt/bird.mp4"));
    playlist->addMedia(QUrl::fromLocalFile("/opt/arrow.mp4"));

    playlist->setPlaybackMode(QMediaPlaylist::Loop);
    playlist->setCurrentIndex(1);
    
    player->setPlaylist(playlist);
    player->setVolume(100);
    
    
    QString RealVideo2=xmlValue[1];
    playlist1= new QMediaPlaylist();
    playlist1->setPlaybackMode(QMediaPlaylist::Loop);
    player1= new QMediaPlayer;
    videoWidget1 = new QVideoWidget;
    playlist1->addMedia(QUrl::fromLocalFile("/opt/abc.mp4"));
    player1->setPlaylist(playlist1);
    player1->setVolume(0);
    
    
    player->setVideoOutput(videoWidget);
    player1->setVideoOutput(videoWidget1);
    playlist->setCurrentIndex(1);
    playlist1->setCurrentIndex(1);
    player->play();
    player1->play();
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      You are adding a few local variables in in MainWindow::MainWindow(QWidget *parent) {}
      which disappear as soon they go out of scope. and this happens way before your main window is shown.
      This includes QGraphicsScene scene; and QGraphicsView view(&scene);
      I bet it is not what you wanted.

      Instead you probably wanted put members to your MainWindow, so add QGraphicsScene scene; QGraphicsView view; to header file
      and just initialize them in constructor before anything else.

      H 1 Reply Last reply
      0
      • A alex_malyu

        You are adding a few local variables in in MainWindow::MainWindow(QWidget *parent) {}
        which disappear as soon they go out of scope. and this happens way before your main window is shown.
        This includes QGraphicsScene scene; and QGraphicsView view(&scene);
        I bet it is not what you wanted.

        Instead you probably wanted put members to your MainWindow, so add QGraphicsScene scene; QGraphicsView view; to header file
        and just initialize them in constructor before anything else.

        H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

        After initializing them in constructor, the scene appears, video music is playing but
        video is not.

        @ header file
        QGraphicsProxyWidget* proxy;
        QGraphicsScene* scene;
        QGraphicsView* view;
        @

        @
        ui->setupUi(this);
        scene = new QGraphicsScene(this);

        ml = new WidgetMarqueeLabel(this);
        ml->setDirection(1);
        ml->setSpeed(1);
        ml->setAlignment(Qt::AlignBottom);
        ml->setText(QString("%1").arg(xmlValue[2]));
        ml->setFont(QFont("Arial", 15,30));
        QGridLayout *layout= new QGridLayout;
        video();
        layout->addWidget(videoWidget,0,0);
        layout->addWidget(videoWidget1,0,1);
        layout->addWidget(ml,1,0,1,2);
        layout->setColumnStretch(0,10);
        layout->setColumnStretch(1,10);
        
        QWidget *window= new QWidget;
        window->setLayout(layout);
        proxy= scene->addWidget(window);
        view = new QGraphicsView(scene);
        view->setFixedSize(800,900);
        view->show();
        

        @

        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