Tickers cannot run into QGridLayout, no moving text can be seen (solved)



  • The Marquee Text could run when below code is used individually
    @
    QMainWindow::setCentralWidget(pTicker);
    @
    Tickers cannot run in QGridLayout, no moving text can be seen, Please help.
    @
    layout->addWidget(pTicker,2,0,1,2);
    @

    @

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QPushButton>
    #include <QGridLayout>
    #include <QLabel>
    #include "ticker.h"
    #include <QMainWindow>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QWidget *window= new QWidget;
    window->setWindowTitle("My App");

    QLabel *label= new QLabel("Hello");
    Ticker* pTicker = new Ticker(this);
    pTicker->setText("hello this is a long text");
    
    QGridLayout *layout= new QGridLayout;
    video();
    
    layout->addWidget(videoWidget,0,0);
    layout->addWidget(videoWidget1,0,1);
    layout->addWidget(label,1,0,1,2);
    layout->addWidget(pTicker,2,0,1,2);                             //doesn't appear when run
    //QMainWindow::setCentralWidget(pTicker);
    
    
    video();
    window->setLayout(layout);
    window->show();
    

    }

    void MainWindow::video()
    {
    playlist= new QMediaPlaylist();
    player= new QMediaPlayer;
    videoWidget = new QVideoWidget;
    playlist->addMedia(QUrl::fromLocalFile("/opt/hotgirl.mp4"));
    player->setPlaylist(playlist);

    playlist1= new QMediaPlaylist();
    player1= new QMediaPlayer;
    videoWidget1 = new QVideoWidget;
    playlist1->addMedia(QUrl::fromLocalFile&#40;"/opt/hotgirl.mp4"&#41;&#41;;
    player1->setPlaylist(playlist&#41;;
    
    
    player->setVideoOutput(videoWidget);
    player1->setVideoOutput(videoWidget1);
    //videoWidget->show();
    playlist->setCurrentIndex(1);
    playlist1->setCurrentIndex(1);
    player->play();
    player1->play();
    

    }

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

    @


  • Moderators

    Whats the type of Ticker class? Can you guarantee that the widget works as expected?

    Also don't set a layout on the QMainWindow.
    Rather set it on a new widget and set this widget as the central widget.



  • it is proven working

    i got it from link below

    http://thisthread.blogspot.sg/2010/07/ticker-timer-event.html


  • Moderators

    [quote author="raven-worx" date="1422612257"]
    Also don't set a layout on the QMainWindow.
    Rather set it on a new widget and set this widget as the central widget.[/quote]
    did you try it?



  • The problem is either the 'Ticker' widget or how you are using this widget in your program. There is no way it has anything to do with the QGridLayout.

    If you substitute this widget with something else (i.e. QLabel with some text set) you should be able to see it in the proper location. At least this would verify your programs use of the QGridLayout.

    I followed the link. I didn't see the download but I did notice references to Qt4 in the description (nothing to Qt5). Maybe something needs to be changed in this widget in order to work with the new version of Qt? (which I assume you are using). Just a thought.



  • The ticker widget used a timerEvent 30 second to call paintEvent repainting saved QString text creating the text shift.

    It is using setCentralWidget setting the moving text in MainWindow central. I tested it working and want to use it at the bottom of MainWindow. It inherit QWidget, i thought i could use it in QGridLayout??


  • Lifetime Qt Champion

    Hi,

    You can't change the layout of a QMainWindow. However if by bottom you mean the status bar, then you can set widgets on it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.