Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. First time, button need double click to trigger. Next time, just one click.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
17 Posts 3 Posters 8.0k Views 2 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.
  • H Offline
    H Offline
    Hung Tran
    wrote on 7 Apr 2017, 04:21 last edited by
    #1

    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 :|

    A 1 Reply Last reply 7 Apr 2017, 04:24
    0
    • H Hung Tran
      7 Apr 2017, 04:21

      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 :|

      A Offline
      A Offline
      ambershark
      wrote on 7 Apr 2017, 04:24 last edited by ambershark 4 Jul 2017, 04:24
      #2

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

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      H 1 Reply Last reply 7 Apr 2017, 04:31
      2
      • A ambershark
        7 Apr 2017, 04:24

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

        H Offline
        H Offline
        Hung Tran
        wrote on 7 Apr 2017, 04:31 last edited by
        #3

        @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">
                 <horstretch>0</horstretch>
                 <verstretch>0</verstretch>
                </sizepolicy>
               </property>
               <property name="text">
                <string/>
               </property>
               <property name="icon">
                <iconset>
                 <normaloff>../../images/player-icon-30.png</normaloff>../../images/player-icon-30.png</iconset>
               </property>
              </widget>
        
        1. Double just happen after start app. When button is triggered, it is not happen
        A 1 Reply Last reply 7 Apr 2017, 04:32
        0
        • H Hung Tran
          7 Apr 2017, 04:31

          @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">
                   <horstretch>0</horstretch>
                   <verstretch>0</verstretch>
                  </sizepolicy>
                 </property>
                 <property name="text">
                  <string/>
                 </property>
                 <property name="icon">
                  <iconset>
                   <normaloff>../../images/player-icon-30.png</normaloff>../../images/player-icon-30.png</iconset>
                 </property>
                </widget>
          
          1. Double just happen after start app. When button is triggered, it is not happen
          A Offline
          A Offline
          ambershark
          wrote on 7 Apr 2017, 04:32 last edited by
          #4

          @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?

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          H 1 Reply Last reply 7 Apr 2017, 04:38
          1
          • A ambershark
            7 Apr 2017, 04:32

            @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?

            H Offline
            H Offline
            Hung Tran
            wrote on 7 Apr 2017, 04:38 last edited by
            #5

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

            A 1 Reply Last reply 7 Apr 2017, 04:43
            0
            • H Hung Tran
              7 Apr 2017, 04:38

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

              A Offline
              A Offline
              ambershark
              wrote on 7 Apr 2017, 04:43 last edited by
              #6

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

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              H 1 Reply Last reply 7 Apr 2017, 05:01
              2
              • A ambershark
                7 Apr 2017, 04:43

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

                H Offline
                H Offline
                Hung Tran
                wrote on 7 Apr 2017, 05:01 last edited by
                #7

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

                Thank so much

                A 1 Reply Last reply 7 Apr 2017, 05:17
                0
                • H Hung Tran
                  7 Apr 2017, 05:01

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

                  Thank so much

                  A Offline
                  A Offline
                  ambershark
                  wrote on 7 Apr 2017, 05:17 last edited by
                  #8

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

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  H 1 Reply Last reply 7 Apr 2017, 07:34
                  1
                  • A ambershark
                    7 Apr 2017, 05:17

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

                    H Offline
                    H Offline
                    Hung Tran
                    wrote on 7 Apr 2017, 07:34 last edited by
                    #9

                    @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

                    A 1 Reply Last reply 7 Apr 2017, 22:33
                    0
                    • H Hung Tran
                      7 Apr 2017, 07:34

                      @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

                      A Offline
                      A Offline
                      ambershark
                      wrote on 7 Apr 2017, 22:33 last edited by
                      #10

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

                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                      H 2 Replies Last reply 10 Apr 2017, 03:44
                      1
                      • A ambershark
                        7 Apr 2017, 22:33

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

                        H Offline
                        H Offline
                        Hung Tran
                        wrote on 10 Apr 2017, 03:44 last edited by
                        #11

                        @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:
                        myMainUi->hide();
                        
                        	if (!openfileContainer) {
                        		openfileContainer = new QWidget();
                        	}
                        
                        	openfileContainer->setStyleSheet("background: black;");
                        	openfileContainer->move(0, 0);
                        	openfileContainer->resize(1920, 1080);
                        	openfileContainer->show();
                        
                        	QFileDialog* dialog = new QFileDialog(openfileContainer);
                        	dialog->setStyleSheet("background: #eee;");
                        	dialog->setFileMode(QFileDialog::ExistingFile);
                        	dialog->setNameFilter(QObject::tr("Clip (*.mkv *.avi *.mp4 *.divx)"));
                        	dialog->setViewMode(QFileDialog::Detail);
                        	dialog->setOption(QFileDialog::DontUseNativeDialog);
                        	dialog->setDirectory(QObject::tr("/home/root/video"));
                        
                        	res = dialog->exec();
                        	openfileContainer->resize(0, 0);
                        	openfileContainer->hide();
                        
                        
                        	myMainUi->show();
                        

                        after that I show myMainUi;

                        myMainUi->show();
                        
                        1. Play video
                                        this->myState.setState(DivXPlayerState::APP_STATE_PLAY);
                        
                        		sleep(2);
                        		myMainUi->hide();
                        		myMainUi->show();
                        

                        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.

                        		this->myState.setState(DivXPlayerState::APP_STATE_PLAY);
                        
                        		sleep(2);
                        		myMainUi->hide();
                        		myMainUi->show();
                        		//new code
                        		myMainUi->setFocusPolicy(Qt::StrongFocus);
                        		myMainUi->setFocus();
                        

                        Do you have any solution for this case?

                        1 Reply Last reply
                        0
                        • A ambershark
                          7 Apr 2017, 22:33

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

                          H Offline
                          H Offline
                          Hung Tran
                          wrote on 10 Apr 2017, 08:11 last edited by
                          #12

                          @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 ?

                          A 1 Reply Last reply 11 Apr 2017, 02:33
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 10 Apr 2017, 21:00 last edited by
                            #13

                            Hi,

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

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            2
                            • H Hung Tran
                              10 Apr 2017, 08:11

                              @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 ?

                              A Offline
                              A Offline
                              ambershark
                              wrote on 11 Apr 2017, 02:33 last edited by
                              #14

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

                              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                              H 1 Reply Last reply 11 Apr 2017, 07:42
                              1
                              • A ambershark
                                11 Apr 2017, 02:33

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

                                H Offline
                                H Offline
                                Hung Tran
                                wrote on 11 Apr 2017, 07:42 last edited by
                                #15

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

                                A 1 Reply Last reply 11 Apr 2017, 21:43
                                0
                                • H Hung Tran
                                  11 Apr 2017, 07:42

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

                                  A Offline
                                  A Offline
                                  ambershark
                                  wrote on 11 Apr 2017, 21:43 last edited by
                                  #16

                                  @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 http://stackoverflow.com/questions/1014822/how-to-know-which-window-has-focus-and-how-to-change-it.

                                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                  H 1 Reply Last reply 18 Apr 2017, 09:11
                                  1
                                  • A ambershark
                                    11 Apr 2017, 21:43

                                    @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 http://stackoverflow.com/questions/1014822/how-to-know-which-window-has-focus-and-how-to-change-it.

                                    H Offline
                                    H Offline
                                    Hung Tran
                                    wrote on 18 Apr 2017, 09:11 last edited by
                                    #17

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

                                    1 Reply Last reply
                                    1

                                    1/17

                                    7 Apr 2017, 04:21

                                    • Login

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