Qt File selector?
-
wrote on 7 May 2021, 15:34 last edited by SPlatten 5 Jul 2021, 15:54
Is there a GUI style file selector available in Qt, I've seen QFileSelector, but it isn't derived from QWidget so I'm not sure if its the thing I'm looking for.
-
@artwaw
I didn't notice it saidQTextEdit
instead ofQLineEdit
:) I'm sure the latter was intended.Yours sounds nice. I don't have Qt here, how does the user know to click what to pull up the
QFileDialog
? "with an icon and no text": does that means something comes up on right-click?wrote on 9 May 2021, 12:32 last edited by artwaw 5 Sept 2021, 14:37@JonB Here, this is taken from one of my projects.
Assume you have UI (in my case it is QDialog for options setting), where QLineEdit nameddbFileEdit
is present. This code is in my ctor:QAction *findFile = new QAction(QIcon("/gfx/file-2.png"),"",this); findFile->setToolTip("Browse for file..."); connect(findFile,&QAction::triggered,this,&optiondlg::selectFile); ui->dbFileEdit->addAction(findFile,QLineEdit::TrailingPosition);
I could go with a lambda instead of the slot but I do some other things there too.
So the idea is that the icon and tooltips are meaningful giving a hint to the user. In my case it looks like this:
I also use this kind of thing when offering users an option to switch between masked/clear text echo with passwords.
EDIT:
For right click you'd need to go w the custom context menu for QLineEdit, this QAction reacts to the regular left click, offering standard QAction features like statusTip and toolTip - I find it less of a hassle than context menus. And it saves ton of space in widget rich UIs too.EDIT2: typos.
-
Is there a GUI style file selector available in Qt, I've seen QFileSelector, but it isn't derived from QWidget so I'm not sure if its the thing I'm looking for.
wrote on 7 May 2021, 16:23 last edited by -
wrote on 7 May 2021, 16:24 last edited by SPlatten 5 Jul 2021, 16:54
@Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.
If this isn't available already then I think I will have to create a custom widget to do it.
-
@Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.
If this isn't available already then I think I will have to create a custom widget to do it.
-
@Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.
If this isn't available already then I think I will have to create a custom widget to do it.
wrote on 7 May 2021, 17:04 last edited by@SPlatten you may also add an action to QLineEdit (I am not sure why you want single line QTextEdit) with an icon and no text. Connect the action to the slot or lamda calling QFileDialog. I do that routinely for browse for location UI features. Once you have the action set you just https://doc.qt.io/qt-5/qlineedit.html#addAction
-
@Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.
If this isn't available already then I think I will have to create a custom widget to do it.
-
@SPlatten you may also add an action to QLineEdit (I am not sure why you want single line QTextEdit) with an icon and no text. Connect the action to the slot or lamda calling QFileDialog. I do that routinely for browse for location UI features. Once you have the action set you just https://doc.qt.io/qt-5/qlineedit.html#addAction
wrote on 7 May 2021, 17:07 last edited by JonB 5 Jul 2021, 17:09@artwaw
I didn't notice it saidQTextEdit
instead ofQLineEdit
:) I'm sure the latter was intended.Yours sounds nice. I don't have Qt here, how does the user know to click what to pull up the
QFileDialog
? "with an icon and no text": does that means something comes up on right-click? -
@artwaw
I didn't notice it saidQTextEdit
instead ofQLineEdit
:) I'm sure the latter was intended.Yours sounds nice. I don't have Qt here, how does the user know to click what to pull up the
QFileDialog
? "with an icon and no text": does that means something comes up on right-click?wrote on 9 May 2021, 12:32 last edited by artwaw 5 Sept 2021, 14:37@JonB Here, this is taken from one of my projects.
Assume you have UI (in my case it is QDialog for options setting), where QLineEdit nameddbFileEdit
is present. This code is in my ctor:QAction *findFile = new QAction(QIcon("/gfx/file-2.png"),"",this); findFile->setToolTip("Browse for file..."); connect(findFile,&QAction::triggered,this,&optiondlg::selectFile); ui->dbFileEdit->addAction(findFile,QLineEdit::TrailingPosition);
I could go with a lambda instead of the slot but I do some other things there too.
So the idea is that the icon and tooltips are meaningful giving a hint to the user. In my case it looks like this:
I also use this kind of thing when offering users an option to switch between masked/clear text echo with passwords.
EDIT:
For right click you'd need to go w the custom context menu for QLineEdit, this QAction reacts to the regular left click, offering standard QAction features like statusTip and toolTip - I find it less of a hassle than context menus. And it saves ton of space in widget rich UIs too.EDIT2: typos.
-
@JonB Here, this is taken from one of my projects.
Assume you have UI (in my case it is QDialog for options setting), where QLineEdit nameddbFileEdit
is present. This code is in my ctor:QAction *findFile = new QAction(QIcon("/gfx/file-2.png"),"",this); findFile->setToolTip("Browse for file..."); connect(findFile,&QAction::triggered,this,&optiondlg::selectFile); ui->dbFileEdit->addAction(findFile,QLineEdit::TrailingPosition);
I could go with a lambda instead of the slot but I do some other things there too.
So the idea is that the icon and tooltips are meaningful giving a hint to the user. In my case it looks like this:
I also use this kind of thing when offering users an option to switch between masked/clear text echo with passwords.
EDIT:
For right click you'd need to go w the custom context menu for QLineEdit, this QAction reacts to the regular left click, offering standard QAction features like statusTip and toolTip - I find it less of a hassle than context menus. And it saves ton of space in widget rich UIs too.EDIT2: typos.
1/9