Display filenames on a QpushButton
Hello ! I'm trying to do a menu where the user can select a file to open just by clicking on a button.
Basically, that means that i want to get all filenames from a directory and create a button for each file (number of file and their names can change).
I managed to get filenames thanks to QFileInfoList but the best i can do is display it in shell...
Is what i'm trying to do even possible, and if so, what do i have to use ?
Hi and welcome to the forums.
Yes that is very possible.
Do you want pushbuttons? You can also use a listwidget which is
a list of strings. it can also have icons etc. ( and each item can be clicked)
But yes you can generate a lots of buttons and use the file name as button text.
( you need a default gui project with mainwindow and place the buttons there )
What will open the file ?
I mean what should happen when you click it ?
Open the file in your own app or call OS to open the default app assigned to that file type?
Also this sample might be useful
Hi. Wouldn't it make more sense to list all the files in a list, and then open the file you want simply by clicking on the corresponding entry in the list? You may even add an "Open" button to each row in such a list, e.g. in the second column, to make it extra clear to the user they can open the file by clicking.
Putting all in a listview would save you such headaches as to dimension the size of your buttons for different filenames and how to layout the buttons if you really have a lot of them. Using a list, you could simply scroll, or resize the column that contains the filename, etc..
Hey ! Yes, that might be more interesting indeed, if the folder contain too many files i'll have trouble keeping enough space for my QPushButtons ^^
Thanks for your answers, i'll definitely check the link you gave me @mrjj :)