lundi 27 juin 2016

Connect toolbar's actions to slots [Qt]


I've wrote my little video player, but now i have a problem: i have a basic functionality, but i can't use toolbar's actions that i've added. So, the whole question is how to use this actions as normal widgets (buttons) and how to connect them to SLOT's? P.S. I''ve added this toolbar via code, not via Designer

Here's the code:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "videowindow.h"
#include "setofbuttons.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    videoWindow *video = new videoWindow;
    const QString &paths = "D:\фото\video\P1150277.MOV";

    QVideoWidget *video_wid = new QVideoWidget;
    video->video_enable(video_wid, paths); // enable video

    setCentralWidget(video_wid);
    setGeometry(200, 200, 600, 800); // setting up the main window

    QWidget *widg = new QWidget;
    SetOfButtons *set = new SetOfButtons; // class instances
    QDockWidget *bottom_panel = new QDockWidget();
    QToolBar *tool = new QToolBar;


    tool->addAction("File"); // there we've got some actions. TODO: appeal to actions
    tool->addAction("Settings");
    tool->addAction("Info");

    set->PlaceSet(widg); // set a layout of buttons into the main window
    bottom_panel->setWidget(widg);
    addDockWidget(Qt::BottomDockWidgetArea, bottom_panel);
    bottom_panel->setFeatures(QDockWidget::NoDockWidgetFeatures); // remove borders
    addToolBar(Qt::TopToolBarArea, tool);
    tool->actions();

    QObject::connect(set->play, SIGNAL (clicked()), video, SLOT (handlePlay())); // connect buttons to slots. when we click, it makes some action (obviously)
    QObject::connect(set->stop, SIGNAL (clicked()), video, SLOT (handleStop()));
    QObject::connect(set->forward, SIGNAL (clicked()), video, SLOT(handleForward())); // 30 seconds. In future i'll make custom change of time in settings.
    QObject::connect(set->backward, SIGNAL (clicked()), video, SLOT(handleBackward())); // ten seconds
}

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

Aucun commentaire:

Enregistrer un commentaire