Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display filenames on a QpushButton
Forum Updated to NodeBB v4.3 + New Features

Display filenames on a QpushButton

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EL_Mambo
    wrote on last edited by
    #1

    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 ?

    DiracsbracketD 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      http://doc.qt.io/qt-5/qtwidgets-dialogs-findfiles-example.html

      1 Reply Last reply
      3
      • E EL_Mambo

        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 ?

        DiracsbracketD Offline
        DiracsbracketD Offline
        Diracsbracket
        wrote on last edited by Diracsbracket
        #3

        @EL_Mambo
        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..

        E 1 Reply Last reply
        3
        • DiracsbracketD Diracsbracket

          @EL_Mambo
          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..

          E Offline
          E Offline
          EL_Mambo
          wrote on last edited by
          #4

          @Diracsbracket
          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 :)

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved