Important: Please read the Qt Code of Conduct -

First time, button need double click to trigger. Next time, just one click.

  • Dear all,

    I met an issue with handle button. I have 4 button on my app. All is handle same way of QT (on_clicked()). However, When I open app, 1 button just need 1 click to trigger action, other must be double click to trigger action. In addition, after buttons are triggered, they just 1 click to trigger action.

    Anyone know this case plz help me. I have tried to find out in google but no result.
    @SebastianM @SGaist =.= sr for tag you on this topic. I need your help :|

  • Moderators

    @Hung-Tran You're going to need to give us a bit more information. You didn't show any code or even say how these buttons were made. Are we talking QtWidgets or Qml? Are they custom buttons? QPushButtons?

    I'd be good if you showed some code. I've never heard of a stock QPushButton requiring more than 1 click to activate. It could be you have something in front of it or it is grabbing focus on the first click before allow the click to activate it. Just guessing though you didn't give any real info.

  • @ambershark
    Addition information:

    1. I QtWidget and QPushButton. I create button by .UI file so code too long. This is small code:
    <item row="2" column="2">
          <widget class="QPushButton" name="Play">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <property name="text">
           <property name="icon">
    1. Double just happen after start app. When button is triggered, it is not happen

  • Moderators

    @Hung-Tran Hmm.. that doesn't help much.

    Is there any way you could write up some small example code/ui file that can duplicate the problem?

  • @ambershark
    Have you met this case before?
    If not, can it happen ?
    Maybe I should look back my code because action after trigger is call another function that need handle by gstreamer.

  • Moderators

    @Hung-Tran I've never seen this happen before in all my 16 years of Qt development.

    Which is why I needed to see what your code was doing both for creation and click handling for the buttons.

    Maybe it's possible that when you click the first click the function that needs the gstreamer handle doesn't get it properly thus making you need that second click to activate. Even though the first click actually did it's job.

    What I would do to test is just add a qDebug or even just a breakpoint on the function called when the button is activated and see if it is getting that signal on the first click.

    Then you know if it's the button activation or what you are trying to do with that activation.

  • @ambershark Thank for your support. I think my code is root cause issue happen. I will debug and show result late.

    Thank so much

  • Moderators

    @Hung-Tran You're welcome :) Let us know what you find out.

  • @ambershark

    Wow, It's difficult to explain to you. But I have short information to you:

    1. I use Qt for GUI that control action of player. And use GStreamer for playback. Don't playback by qt because qt can't control hardward as my expected.
    2. GUI action will call API of GStreamer.
    3. Before playback by Gstreamer, GUI action as expected. But When playback by GStreamer, I control media output by Qt. Output will scale full screen after that I call GUI control play,stop, trick play...So when this GUI appear, I think it is in behind of media output so I need click first time to make focus on GUI and one more to trigger action.
      => Do you understand what I say and do you have any solution for this case ?
      Or may be it is bug of Wayland because output is shown on wayland Platform.

    Thank you

  • Moderators

    @Hung-Tran Ok yea I get it now. You explained it very well.

    My guess based on what you said is that it is a problem with how you get focus to a window in your window manager.

    Which window manager are you using? Most can be set to activate and pass mouse click, or just activate window on click, etc.

    So with that in mind a quick test to see if you are having a "focus click" then "activate" click is to click somewhere else in that GUI window that pops up. This will focus it. Then click your button to activate. If it works with 1 click then focus is your issue. If not there may be something deeper going on.

    Either way with a bit more info I might be able to suggest some possible fixes.

    Also, quick note on wayland.. In my opinion there are still a lot of problems with wayland. I just don't feel it's ready for prime time yet. This could definitely be a problem related to wayland, but you can always test on xorg or something to see if the problem goes away. That would let you know if it's a wayland issue or not.

  • @ambershark

    This is my process:

    1. App run, QMainWindow show QWidget myMainUi
    2. on myUi have Open button, when click Open button then QFileDialog appear ( I want QDialog appear on middle screen so I create new QWidget *openfileContainerwith full screen that contain QFileDialog).
    3. After i select video file (QFileDialog close native) and I hide openfileContainer:
    	if (!openfileContainer) {
    		openfileContainer = new QWidget();
    	openfileContainer->setStyleSheet("background: black;");
    	openfileContainer->move(0, 0);
    	openfileContainer->resize(1920, 1080);
    	QFileDialog* dialog = new QFileDialog(openfileContainer);
    	dialog->setStyleSheet("background: #eee;");
    	dialog->setNameFilter(QObject::tr("Clip (*.mkv *.avi *.mp4 *.divx)"));
    	res = dialog->exec();
    	openfileContainer->resize(0, 0);

    after that I show myMainUi;

    1. Play video

    From now, I don't know why APP can not focus to myMainUi after I show it. I tried to set APP focus on myMainUi but it does not work.

    		//new code

    Do you have any solution for this case?

  • @ambershark I also have concern about:

    When I call:

    gst_element_set_state(myPipeLine, GST_STATE_PLAYING);

    It means APP playback by GStreamer and media output set full screen.
    After that, I show myMainUi so I think media output overlay UI of APP because Media Output is independent with UI of app. If it is reason, how I can fix it ?

  • Lifetime Qt Champion


    Since you seem to be using low-level GStreamer code then you should consider the QtGStreamer module.

  • Moderators

    @Hung-Tran Well the problem here is getting focus to your window. When gstreamer takes over you lose focus.

    I don't think you can get focus back in linux without user intervention. It's been a while since I tested this so you can try and find out.

    The calls you need to attempt to gain focus are activateWindow() and raise() both are part of QWidget.

    Like I said though, no guarantee that you will get focus. That is up to the window manager and most these days prevent applications from "stealing" focus without user interaction. This is true in Windows and OSX as well.

  • @ambershark I have a question:
    How to know where mouse focus on when app running ?
    I'm trying get focus to control UI but I have no luck. So I want to check when app change state, where mouse focus on.

  • Moderators

    @Hung-Tran That is something you will need to do specific to each OS. There is no way to do it with Qt (that I'm aware of).

    For instance, here is how you would do it with X11

  • @ambershark Sry for late reply.

    In my case, I finally uses code C to create fake clicking on UI to active UI. I can't solve this issue by Qt5 so I have no choose for this issues. It's not my expected but It can make my APP better than.

Log in to reply