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. How to unclick a QPushButton
Forum Updated to NodeBB v4.3 + New Features

How to unclick a QPushButton

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 379 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by
    #1

    i am able to click a push button but not able to unclick it.This line button->setDown(false); does not unclick the button,

    bool eventFilter(QObject* obj, QEvent* event)
    {
    	if (obj->isWidgetType())
    	{
    		// Check if the event is a KeyPress or KeyRelease
    		if (event->type() == QEvent::KeyPress)
    		{
    			QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
    			// Check if Ctrl is pressed (Ctrl key is Qt::ControlModifier)
    			if (keyEvent->modifiers() == Qt::ControlModifier)
    			{
    				
    				// Check if the QColorDialog is currently open
    				QColorDialog* colorDialog = qobject_cast<QColorDialog*>(obj);
    				if (colorDialog)
    				{
    					// Find the "Pick Screen Color" button and click it programmatically
    					QList<QPushButton*> buttons = colorDialog->findChildren<QPushButton*>();
    					for (QPushButton* button : buttons)
    					{
    						if (button->text().contains("Pick Screen Color", Qt::CaseInsensitive))
    						{
    							button->click();
    							break;
    						}
    					}
    				}
    			}
    		}
    		else if (event->type() == QEvent::KeyRelease)
    		{
    			QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
    			// Check if Ctrl is released (Ctrl key is Qt::ControlModifier)
    			if (keyEvent->key() == Qt::Key_Control)
    			{
    				// Check if the QColorDialog is currently open
    				QColorDialog* colorDialog = qobject_cast<QColorDialog*>(obj);
    				if (colorDialog)
    				{
    					// Find the "Pick Screen Color" button and uncheck it programmatically
    					QList<QPushButton*> buttons = colorDialog->findChildren<QPushButton*>();
    					for (QPushButton* button : buttons)
    					{
    						if (button->text().contains("Pick Screen Color", Qt::CaseInsensitive))
    						{
    							// Uncheck the button if it is checked (simulate unclicking)
    							
    							button->setDown(false);
    							break;
    						}
    					}
    				}
    			}
    		}
    	}
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      summit
      wrote on last edited by
      #6

      This button requires a esc event to be called to be unselected.

      QKeyEvent escapeEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
      QCoreApplication::sendEvent(button, &escapeEvent);

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        What are you trying to achieve? Click a button? See https://doc.qt.io/qt-6/qabstractbutton.html#click

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • S Offline
          S Offline
          summit
          wrote on last edited by summit
          #3

          @Christian-Ehrlicher i want to unclick the pick screen color button after it has been clicked , currently i am not able to do it with code.

          I need to manually click once with the mouse to unclick it.

          ColorDialog.png

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Why do you want to do this? I would guess it's a button with checkable property so you have to reset this. Simply look in the source code to see if I'm correct.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • S Offline
              S Offline
              summit
              wrote on last edited by
              #5

              @Christian-Ehrlicher This is not a checkable button.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                summit
                wrote on last edited by
                #6

                This button requires a esc event to be called to be unselected.

                QKeyEvent escapeEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
                QCoreApplication::sendEvent(button, &escapeEvent);

                1 Reply Last reply
                0
                • S summit has marked this topic as solved on
                • Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #7

                  The dialog literally says "Press ESC to cancel" :)


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  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