Results 1 to 4 of 4

Thread: an Unchekcable push Button is checked and stays checked when used with qfiledialog

  1. #1
    Join Date
    Jul 2011
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question an Unchekcable push Button is checked and stays checked when used with qfiledialog

    Hi I have strange problem.
    I have a widget gui with a not checkable button that when pressed opens a file dialog.

    here is the signal

    connect(ui->loadcsv,SIGNAL(pressed()),this, SLOT(fromcsv()));

    and the start of the slot

    void newinstrument::fromcsv(){
    QString line,filename;
    QStringList filesnames;

    QFileDialog dialog(this);
    dialog.setFileMode(QFileDialog::ExistingFile);
    dialog.setDirectory(folder);
    if(dialog.exec())filesnames=dialog.selectedFiles() ;

    .....

    This always leaves the loadcsv button as checked.

    although this being a noncheckable button I still tried to explicitly put the status of the button as unchecked before returning the fromscv slot but the result do not change. After being pressed once the button stays always checked but other from that everything seem to work fine (I called this checked due only to the visual effect but really is not a checked status as a second click does not put the button with the visual aspect of an unchecked button).

    any hints would be welcome

    P.s.
    I'm using qt12.1 from opensuse leap 15.0

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,324
    Thanks
    36
    Thanked 1,527 Times in 1,478 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: an Unchekcable push Button is checked and stays checked when used with qfiledial

    Recommendation 1: use the button's clicked() signal
    Recommendation 2: use QFileDialog::getOpenFileNames()

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    artome (21st February 2019)

  4. #3
    Join Date
    Jul 2011
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: an Unchekcable push Button is checked and stays checked when used with qfiledial

    The clicked signal worked as i always use pressed signal i'll try to understand the difference.
    cheers

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,987
    Thanks
    232
    Thanked 628 Times in 618 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: an Unchekcable push Button is checked and stays checked when used with qfiledial

    The clicked signal worked as i always use pressed signal i'll try to understand the difference.
    The difference is that the pressed() signal is emitted as soon as the mouse goes down on the button. The clicked() signal is emitted only when the mouse goes down and then comes back up while on the button. This difference has at least three consequences:

    - If you connect to pressed(), then there is no way for the user to cancel the action - whatever is in the slot gets executed as soon as the mouse goes down.
    - If the slot connected to pressed() causes the button to lose focus, then the button will never see a mouse release so it stays depressed. This is what happened for you.
    - If you connect to clicked() and the user presses the mouse on the button but then moves off the button to release the mouse, there is no signal. This lets the user "cancel" the click before anything happens. The clicked() signal is emitted only if the mouse down and up happen while the mouse is on the button. (The mouse can move off the button while it is pressed, but if it moves back on when it is released, the signal will be emitted).

    In general, you should always connect to the clicked() signal for a good user experience.
    Last edited by d_stranz; 22nd February 2019 at 16:22.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 28th July 2012, 16:09
  2. How to checked if button is clicked
    By stbb24 in forum Newbie
    Replies: 3
    Last Post: 5th June 2012, 06:04
  3. Replies: 1
    Last Post: 26th April 2012, 10:36
  4. Replies: 2
    Last Post: 6th June 2011, 09:40
  5. Replies: 3
    Last Post: 26th July 2010, 02:23

Tags for this Thread

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.