Results 1 to 1 of 1

Thread: Overlay widgets

  1. #1
    Join Date
    Sep 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Overlay widgets

    I am trying to overlay a few buttons over my video player.

    I have added a new class called overlay.cpp that subclassed a QWidget for the overlay purpose.

    What I did in my code is to overlay button onto the video. In my centralWidget I have added a verticalLayout and morph it into a QWidget. The video was added into this verticalLayout. Upon program is running, the video is playing well. However, what's not working is the overlay of the button. The background doesn't seem to appear transparent even though it was set. I am not sure what is causing it to not appear transparent.

    My code is as follows:

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[]){
    5.  
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9.  
    10. return a.exec();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent):QMainWindow(parent),
    5. ui(new Ui::MainWindow){
    6. ui->setupUI(this);
    7. initializeVideo();
    8. initializeButton();
    9. }
    10.  
    11. MainWindow::~MainWindow(){
    12.  
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::initializeVideo(){
    17.  
    18. QVideoWidget *v_widget = new QVideoWidget;
    19. QMediaPlayer *m_player = new QMediaPlayer;
    20.  
    21. m_player->setMedia(QUrl::fromLocalFile("C:/user/Desktop/video.wmv"));
    22. m_player->setVideoOutput(v_widget);
    23.  
    24. ui->verticalLayout->addWidget(v_widget);
    25.  
    26. m_player->player();
    27. v_widget->show();
    28.  
    29. }
    30.  
    31. void MainWindow::initializeButton(){
    32.  
    33. QFrame *b_frame = new QFrame;
    34. QGridLayout *grid = new QGridLayout;
    35. b_frame->setLayout(grid);
    36.  
    37. b_frame->setAttribute(Qt::WA_TranslucentBackground, true);
    38.  
    39. QPushButton *buttonStop = new QPushButton;
    40. buttonStop->setText("STOP");
    41. grid->addWidget(buttonStop, 0, 0, Qt::AlignTop);
    42.  
    43. overlay *overlay_1 = new overlay;
    44. QGridLayout *gridLayout = new QGridLayout;
    45. gridLayout->addWidget(b_frame);
    46. overlay_1->setLayout(gridLayout);
    47.  
    48. overlay_1->setParent(ui->verticalWidget);
    49. overlay_1->show();
    50.  
    51. b_frame->show();
    52.  
    53. }
    To copy to clipboard, switch view to plain text mode 
    overlay.cpp
    Qt Code:
    1. #include "overlay.h"
    2. overlay::overlay(QWidget *parent): QWidget(parent){
    3.  
    4. this->setAttribute(Qt::WA_TranslucentBackground, true);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 9th September 2015 at 15:46. Reason: missing [code] tags

Similar Threads

  1. Replies: 3
    Last Post: 18th July 2019, 10:25
  2. QScrollView Overlay
    By EricTheFruitbat in forum Qt Programming
    Replies: 5
    Last Post: 27th December 2006, 09:29
  3. Overlay
    By ToddAtWSU in forum Qt Programming
    Replies: 21
    Last Post: 24th May 2006, 13:15
  4. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.