Results 1 to 6 of 6

Thread: UI to preview pictures and music

  1. #1
    Join Date
    Dec 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default UI to preview pictures and music

    Hi,

    I just found out Qt not long ago and really like its interface. But it's kinda complicated when most of the examples are pure coding. I'm trying to do it with the design part...
    Right now I'm making a file viewer. So I have a treeView, a graphicsView, a listView and buttons.



    I worked out how to put a directory browser in the treeView, and when a file clicked, the path goes to the lineEdit. Now I want the graphicsView to show the picture if one is clicked in the treeList. And the path of the music will go to the listView when button Add is pressed. Any advice how to do that?

    I'd appreciate if you actually explain it so I can understand, I don't like "copy and paste" the code, it makes me feel very bad.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UI to preview pictures and music

    You've reached the point where you need to start coding. It is a good sign that you feel bad just copy/pasting the code, but that shouldn't hold you from it when learning. If you are going to copy/paste, find out what the piece of code does. In your case it would be good to start learning about signals and slots. Then, since you are using views, learn about model/view programming.

    We can say a lot about what you should do, but we can only be really helpful if we know what exactly you do not understand.

    In any case:
    Write a slot that copies the current string value from your line edit to the list view.
    Write a slot that loads a picture from a file and passes it to the graphics view (look at the drop-site example for similar behavior).
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Dec 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UI to preview pictures and music

    Let's see, I have achieved getting the path when select an item. But GraphicsView widget is very confusing at the moment.

    Qt Code:
    1. void FileBrowser::on_treeView_clicked(QModelIndex index)
    2. {
    3. QString path;
    4. if(index.isValid())
    5. {
    6. ui->lineEdit->setText(model.filePath(index));
    7. path = lineEdit.Text();
    8. scene.addPixmap(path);
    9. QGraphicsView view(&scene);
    10. view.show();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    So, I tried to display the item when it is clicked, but I can't get the path from lineEdit.


    Added after 18 minutes:


    I also got the path added to listView using this:

    Qt Code:
    1. void FileBrowser::on_addButton_clicked()
    2. {
    3. QString musicPath;
    4. path = QFileDialog::getOpenFileName(this,
    5. "Choose music:",
    6. QString::null,
    7. QString::null);
    8.  
    9. ui->listWidget->addItem(musicPath);;
    10. }
    To copy to clipboard, switch view to plain text mode 

    But it's not actually what I wanted, because I have to browse the file. But all the time Qt said "lineEdit is not declared in this scope". Can I use QLineEdit::copy() or something?
    Last edited by Akira; 15th December 2010 at 16:54.

  4. #4
    Join Date
    Dec 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UI to preview pictures and music

    it has been solved!
    basically I need to "access" the widget, not "connect" them.

    It's even much much easier to use label to display the image, not GraphicsView so I'll take a note on that.

    Last thing, now I have the path, can anyone tell me the quickest way to play the music with an event pushButton_clicked()?

    I tried Phonon::MediaObject and music->play but it doesn't work... (connect2: ld has 1 exit status or something along that line)

  5. #5
    Join Date
    Dec 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UI to preview pictures and music

    Qt Code:
    1. QString path = ui->listWidget->currentItem()->text();
    2. Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory,
    3. Phonon::MediaSource(path));
    4. music->play();
    To copy to clipboard, switch view to plain text mode 
    Error: collect2: ld returned 1 exit status

  6. #6
    Join Date
    Dec 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UI to preview pictures and music

    Solved.
    Have to put QT += phonon in .pro file

    Thank you very much.

Similar Threads

  1. Replies: 19
    Last Post: 13th May 2013, 12:17
  2. Do you listen music while programming?
    By Raccoon29 in forum General Discussion
    Replies: 20
    Last Post: 30th January 2011, 09:49
  3. Free music for a software
    By ale6111 in forum General Programming
    Replies: 3
    Last Post: 28th July 2010, 08:47
  4. Programmer for Music Application
    By jlazarus in forum Jobs
    Replies: 0
    Last Post: 29th January 2010, 04:57
  5. playing music from a database
    By Baasie in forum Qt Programming
    Replies: 5
    Last Post: 19th January 2010, 11:48

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.