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. Add Widget to QStackedWidget "pages"

Add Widget to QStackedWidget "pages"

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.0k 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.
  • MichRX7M Offline
    MichRX7M Offline
    MichRX7
    wrote on last edited by
    #1

    Ok, so I have a QStackedWidget with layout1 and layout2 as child "pages" when a Qpushbutton is clicked I want to add a widget to layout2 (that plays a video).

    So, in my buttonclicked() I have:
    QMediaPlayer *player = new QMediaPlayer;
    QVideoWidget *vw = new QVideoWidget;
    player->setVideoOutput(vw);
    player->setVolume(50);
    player->setMedia(QUrl::fromLocalFile("/home/pi/Videos/testvideo.wmv"));
    vw->show();
    player->play();

    This works and plays the video, but it opens a new "window" when I call vw->show(); instead of that I want to put the QVideoWidget "vw" on my child page "layer2" of my QStackedWidget "stackedWidget".

    I tried layer2->addWidget(vw); but obviously that was wrong, lol...

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MichRX7 said in Add Widget to QStackedWidget "pages":

      I tried layer2->addWidget(vw); but obviously that was wrong, lol...

      Why is this wrong?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      MichRX7M 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @MichRX7 said in Add Widget to QStackedWidget "pages":

        I tried layer2->addWidget(vw); but obviously that was wrong, lol...

        Why is this wrong?

        MichRX7M Offline
        MichRX7M Offline
        MichRX7
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in Add Widget to QStackedWidget "pages":

        @MichRX7 said in Add Widget to QStackedWidget "pages":

        I tried layer2->addWidget(vw); but obviously that was wrong, lol...

        Why is this wrong?

        Well, when I add that line of code it tells me: "Use of undeclared identifier 'layer2'" and won't compile, so I assumed it was quite wrong.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You have to store it as member if you want to access it later in another function in your class - c++ basics...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • MichRX7M Offline
            MichRX7M Offline
            MichRX7
            wrote on last edited by
            #5

            I understand the basics, but being new to QT I didn't understand why I could set aspects of a QLabel on my layer1 in that same function, but not this on my layer2? If I "drew" the QStackedWidget and the layer1/layer2 pages in the UI how can I set that layer2 so that it is accessible in my button click function?

            Thank you for your input.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @MichRX7 said in Add Widget to QStackedWidget "pages":

              I understand the basics,

              I doubt so - storing some objects and pointers in a class and adding getter/accessors to them so they're accessible from the outside has nothing to do with Qt. It's plain object oriented c++.

              What Qt can do for you here is that you can emit a signal when the QPushButton is clicked which you connect to a slot on the second tab. But that's more or less the same than simply using functions, maybe a little bit easier.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @MichRX7 said in Add Widget to QStackedWidget "pages":

                Well, when I add that line of code it tells me: "Use of undeclared identifier 'layer2'" and won't compile, so I assumed it was quite wrong.

                Just as a note. the code you show says "layout2" and not "layer"
                so did you use the right name when added it to the layout ?

                layer2->addWidget(vw); --> layout2->addWidget(vw);

                It is the right way.

                The reason they come windows, when you call show() is that they have no parent
                QVideoWidget *vw = new QVideoWidget; ( no parent assigned )
                So adding them to the layout would solve that.

                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