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.
http://img816.imageshack.us/img816/654/42269357.jpg
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. :)
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).
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.
Code:
void FileBrowser
::on_treeView_clicked(QModelIndex index
) {
if(index.isValid())
{
ui->lineEdit->setText(model.filePath(index));
path = lineEdit.Text();
scene.addPixmap(path);
view.show();
}
}
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:
Code:
void FileBrowser::on_addButton_clicked()
{
"Choose music:",
ui->listWidget->addItem(musicPath);;
}
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?
Re: UI to preview pictures and music
it has been solved!
basically I need to "access" the widget, not "connect" them. :D
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)
Re: UI to preview pictures and music
Code:
QString path
= ui
->listWidget
->currentItem
()->text
();
Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory,
Phonon::MediaSource(path));
music->play();
Error: collect2: ld returned 1 exit status
Re: UI to preview pictures and music
Solved.
Have to put QT += phonon in .pro file
Thank you very much.