Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem related to clicked signal?
Forum Updated to NodeBB v4.3 + New Features

Problem related to clicked signal?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.5k Views 1 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    While i am pressing a button and releasing it outside the button area how clicked signal is calling its corresponding slot. i mean it should not be called. What may be the wrong in my code.
    @ QObject::connect (button1, SIGNAL(clicked()), &a, SLOT(quit()));@

    Pratik Agrawal

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      There's nothing wrong with this connect().

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

        then how i am getting this type of behavior?

        Pratik Agrawal

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          Can't say. Got more code to show? The connect statement doesn't influence when signals are emitted, so if you say clicked() is emitted in your situation, there might be some other influence playing part.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pratik041
            wrote on last edited by
            #5

            The code is following

            @button.cpp

            ofi_vc_gui_button::ofi_vc_gui_button (QWidget *parent):
            QPushButton(parent)
            {
            button_width = 0;

            button_height = 0;
            
            tt_width = 0;
            
            num_of_images = 0;
            num_of_states = 0;
            m_hovered = false;
            m_pressed = false;
            
            link_flag = false;
            tt_flag = true;
            
            tm_flag = false;
            key_support = false;
            is_animate = false;
            image_index = 0;
            flag = false;
            btn_state = false;
            
            memset (button_txt, NULL, OFI_VC_GUI_BTN_MAX_TXT_LEN);
            

            }

            void ofi_vc_gui_button::create_button (QPixmap &image,QString tool_tip_text,char *btn_txt,bool erase_bkground, QRect rect,
            bool key_supp,
            int num_states)

            {
            pixmap = image;
            button_width = rect.width ();

            button_height = rect.height();
            
            num_of_states = num_states;
            num_of_images = pixmap.width()/button_width;
            
            strcpy_s(button_txt, btn_txt);
            
            tt_text = tool_tip_text;
            
            key_support = key_supp;
            qDebug ()<<"key support";
            
            create_region ();
            
            target = QRectF(0.0, 0.0, button_width, button_height);
            draw_button (OFI_VC_GUI_BTN_STATE_NORMAL);
            

            }

            void ofi_vc_gui_button::keyPressEvent (QKeyEvent *event)
            {

            if (key_support == true) {
            
                if (event->key () == Qt::Key_Enter) {
            
                    event->accept ();
            
                    emit clicked();
                } else {
            
                    event->ignore ();
                }
            }
            

            }

            void ofi_vc_gui_button::mousePressEvent (QMouseEvent *e)
            {
            qDebug ()<<"mouse press";
            qDebug ()<<e->globalPos ();

                // Check the button is enabled or not.
                if (this->isEnabled ()) {
                    draw_button (OFI_VC_GUI_BTN_STATE_PUSHED);
                }
            QPushButton::mousePressEvent (e);
            

            }

            void ofi_vc_gui_button::mouseMoveEvent (QMouseEvent *e)
            {
            qDebug ()<<this;
            qDebug()<<QApplication::widgetAt (e->globalPos ());
            if (!(QApplication::widgetAt (e->globalPos ()) == this)) {
            qDebug ()<<"mouse move";
            qDebug()<< e->pos ();
            draw_button (OFI_VC_GUI_BTN_STATE_NORMAL);
            }
            QPushButton::mouseMoveEvent (e);
            }

            void ofi_vc_gui_button::mouseReleaseEvent (QMouseEvent *e)
            {
            qDebug()<<e->globalPos ()<<QApplication::widgetAt (e->globalPos ());
            qDebug ()<<"mouse release";

            if (num_of_states == 2) {
            
                if (flag) {
                    draw_button (OFI_VC_GUI_BTN_STATE_NORMAL);
                    flag = false;
                } else {
                    draw_button (OFI_VC_GUI_BTN_STATE_PUSHED);
                    flag = true;
                }
            } else {
                draw_button (OFI_VC_GUI_BTN_STATE_HOVER);
            }
            
            
            QPushButton::mouseReleaseEvent (e);
            

            }

            ofi_vc_gui_button::paintEvent(){
            ..........................

            .................
            }

            main.cpp

            #include <QtGui/QApplication>
            #include "ofi_vc_gui_button.h"

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            QWidget window;

            int   button_states = 3;
            int   tooltip_width = 57;
            
            QRect   rect(20, 30, 47, 51);
            QPixmap pixmap(":/images/endcall.png");
            char    btn_txt[30] = "";
            QColor  col(0, 255, 255);
            
            QString font_type("Calibri");
            
            QString tt_text("normal text");
            QString ptt_text("pushed state");
            QString dtt_text("disable text");
            QString dptt_text("disable pushed");
            
            
            
            window.setFocusPolicy (Qt::TabFocus);
            
            bool erase_bkground = false;
            ofi_vc_gui_button *button1  = new ofi_vc_gui_button(&window);
            button1->create_button (pixmap,
                                    tt_text,
                                    btn_txt,
                                    erase_bkground,
                                    rect,
                                    false,
                                    button_states);
            
            button1->set_link_flag (false);
            
            button1->set_text_color (col);
            button1->set_font(font_type);
            button1->setGeometry(60, 70, 80, 90);
            
            
            window.setAttribute (Qt::WA_AlwaysShowToolTips, true);
            
            pixmap.load (":/images/record.png");
            rect = QRect(60, 50, 17, 14);
            button_states = 3;
            
            ofi_vc_gui_button *button2 = new ofi_vc_gui_button(&window);
            
            button2->create_button (pixmap,
                                    tt_text,
                                    btn_txt,
                                    erase_bkground,
                                    rect,
                                    button_states);
            
            //button2->activate_tool_tip (false);
            button2->setGeometry (180,200,60,70);
            
            button_states = 2;
            rect = QRect(100, 150, 17, 16);
            ofi_vc_gui_button *button3 = new ofi_vc_gui_button(&window);
            
            pixmap.load (":/images/audio.png");
            button3->create_button (pixmap,
                                    tt_text,
                                    btn_txt,
                                    erase_bkground,
                                    rect,
                                    button_states);
            
            button3->setGeometry (100,150,120,63);
            //button3->set_button_state (true);
            
            button2->enable_button (false);
            
            
            QObject::connect (button1, SIGNAL(clicked()), &a, SLOT(quit()));
            
            qDebug ()<<"key support";
            

            #if defined(Q_WS_S60)
            window.showMaximized();
            #else
            window.show();
            #endif

            return a.exec&#40;&#41;;
            

            }

            @

            Pratik Agrawal

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              return is handled by the dialog, if the button is a default button.
              event->ignore (); means the button ignores the event and it is propagated to the parent widget.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0

              • Login

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