Results 1 to 5 of 5

Thread: Fill in lineedit from QFileDialog

  1. #1
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Fill in lineedit from QFileDialog

    Hi All,
    I have a lineedit that I'd like to be filled in from a QFileDialog. However the way I'd like it to be filled is if the user clicks on the lineedit a QFiledialog opens and the user selects a file. However when I click on the ui and the line edit and go to slots there's no clicked(), what slot do I use to select "clicked on box". Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Fill in lineedit from QFileDialog

    Qt Code:
    1. void XXX::mySlot() {
    2. QString path = QFileDialog::getOpenFileName(...);
    3. if(path.isEmpty()) return;
    4. ui->myLineDit->setText(path);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fill in lineedit from QFileDialog

    If you want to detect clicks on the line edit, you'll either have to derive from QLineEdit and implement the mouse handling in your subclass, or create an event filter that does the mouse handling and install it on the normal QLineEdit instance.

    Cheers,
    _

  4. #4
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Fill in lineedit from QFileDialog

    "If you want to detect clicks on the line edit, you'll either have to derive from QLineEdit and implement the mouse handling in your subclass, or create an event filter that does the mouse handling and install it on the normal QLineEdit instance."

    Thanks so I take it this is not as easy as I thought and might need quite a bit more practice at Qt
    Last edited by knobby67; 18th August 2014 at 17:56.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Fill in lineedit from QFileDialog

    Quote Originally Posted by knobby67 View Post
    Thanks so I take it this is not as easy as I thought and might need quite a bit more practice at Qt
    It is not difficult at all. Have a look at docs of QObject::installEventFilter(). You will want to handle QEvent::MouseButtonRelease.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 7
    Last Post: 5th March 2014, 17:36
  2. Replies: 1
    Last Post: 9th May 2011, 15:19
  3. Fill input in QWebView
    By RzuF in forum Qt Programming
    Replies: 5
    Last Post: 19th December 2010, 09:48
  4. QGraphicsTextItem+trasparent fill+png
    By nicolas1 in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2008, 00:23
  5. lineedit fill in new dialog window.
    By mkarakaplan in forum Newbie
    Replies: 1
    Last Post: 7th October 2007, 07:00

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.