Results 1 to 3 of 3

Thread: Need Help with Layouts

  1. #1
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Need Help with Layouts

    Hi,

    I have trouble applying layout dynamically to my main window. i have some button widgets with layouts applied on main window now I have to add the video widget dynamically on the top of my button widgets. When I add the video widget, the layout is not applied properly to it so that I can't able to resize the video. I need some help in this issue. Here I am copying my code, Please go through it. I am also attaching my two images desired image and getting image.

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QMainWindow>
    6. #include <phonon/audiooutput.h>
    7. #include <phonon/seekslider.h>
    8. #include <phonon/mediaobject.h>
    9. #include <phonon/volumeslider.h>
    10. #include <phonon/backendcapabilities.h>
    11. #include <phonon/VideoWidget>
    12. #include <phonon/VideoPlayer>
    13. #include <QSplitter>
    14. #include <QUrl>
    15. #include <QHBoxLayout>
    16.  
    17. namespace Ui {
    18. class MainWindow;
    19. }
    20.  
    21. class MainWindow : public QMainWindow {
    22. Q_OBJECT
    23. public:
    24. MainWindow(QWidget *parent = 0);
    25. ~MainWindow();
    26.  
    27. protected:
    28. void changeEvent(QEvent *e);
    29.  
    30. private:
    31. Ui::MainWindow *ui;
    32. Phonon::MediaObject *mediaObject;
    33. Phonon::AudioOutput *audioOutput;
    34.  
    35.  
    36. };
    37.  
    38. #endif // MAINWINDOW_H
    39.  
    40. // .CPP file
    41.  
    42. #include "mainwindow.h"
    43. #include "ui_mainwindow.h"
    44. #include <QDebug>
    45. MainWindow::MainWindow(QWidget *parent) :
    46. QMainWindow(parent),
    47. ui(new Ui::MainWindow)
    48. {
    49. ui->setupUi(this);
    50. this->mediaObject = new Phonon::MediaObject(this);
    51. this->audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
    52.  
    53. Phonon::createPath(mediaObject, audioOutput);
    54. Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(this);
    55. videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio4_3);
    56.  
    57. videoWidget->setGeometry(10,20,500,250);
    58.  
    59. Phonon::createPath(mediaObject, videoWidget);
    60. QUrl url("C:\\Users\\Bala\\Music\\3.Idiots-Give.Me.Some.Sunshine.mkv");
    61. mediaObject->setCurrentSource(url);
    62. mediaObject->setTickInterval(1000);
    63. connect(mediaObject, SIGNAL(finished()), mediaObject, SLOT(deleteLater()));
    64. connect(ui->pause,SIGNAL(clicked()),mediaObject,SLOT(pause()));
    65. connect(ui->play,SIGNAL(clicked()),mediaObject,SLOT(play()));
    66. connect(ui->stop,SIGNAL(clicked()),mediaObject,SLOT(stop()));
    67. Phonon::SeekSlider *slider = new Phonon::SeekSlider(this);
    68. slider->setMediaObject(mediaObject);
    69.  
    70. slider->setGeometry(504,393,84,19);
    71. slider->show();
    72.  
    73. QHBoxLayout *layout = new QHBoxLayout;
    74. layout->addWidget(slider);
    75. ui->splitter->setLayout(layout);
    76.  
    77. ui->verticalLayout->addWidget(videoWidget,0,Qt::AlignTop); // Adding video widget to vertical layout
    78. }
    79.  
    80. MainWindow::~MainWindow()
    81. {
    82. delete ui;
    83. }
    84.  
    85. void MainWindow::changeEvent(QEvent *e)
    86. {
    87. QMainWindow::changeEvent(e);
    88. switch (e->type()) {
    89. case QEvent::LanguageChange:
    90. ui->retranslateUi(this);
    91. break;
    92. default:
    93. break;
    94. }
    95. }
    To copy to clipboard, switch view to plain text mode 

    Thank You,

    Baluk
    Attached Images Attached Images
    Last edited by baluk; 20th October 2010 at 18:26.

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need Help with Layouts

    Hi,

    You have to add several widgets to your vertical layout : both the video player and the frame with controls. The layout has to be applied to your entire dialog also, to make it stretch with the dialog.

    It is helpful if you first create the form with Qt Designer. Then you can see the effects of the layout you apply.

    You can use a 'frame' instead of the video player window. You can even promote the frame to the videowidget if you like, so you can do everthing in Qt Designer.

    Best regards,
    Marc

  3. The following user says thank you to marcvanriet for this useful post:

    baluk (21st October 2010)

  4. #3
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need Help with Layouts

    Thanks marcvanrie, It worked -.

Similar Threads

  1. Can Layouts Stretch to Fit?
    By kylemhall in forum Newbie
    Replies: 2
    Last Post: 17th December 2009, 15:37
  2. Layouts
    By csvivek in forum Qt Tools
    Replies: 3
    Last Post: 7th May 2008, 07:22
  3. Layouts
    By Dumbledore in forum Qt Tools
    Replies: 1
    Last Post: 14th October 2007, 01:01
  4. Layouts - Name cant be set
    By manivannan_1984 in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2006, 18:38
  5. 2 Questions about layouts
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2006, 13:54

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.