Results 1 to 11 of 11

Thread: How to know whether a pushbutton is highlighted?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to know whether a pushbutton is highlighted?

    What exactly does refresh() do? Why do you need to call it? Why don't you just intercept the focus-in event of the button you want?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Apr 2013
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to know whether a pushbutton is highlighted?

    Hi,
    I didnt put any break points. Instead of refresh() I put the below code in the if condition to test. But the message box didnt pop up
    void testApp::keyPressEvent(QKeyEvent *event)
    {
    if(event->key() == Qt::Key_Down && buttons[9]->hasFocus())
    {

    QMessageBox msgBox;
    msgBox.setText("The document has been modified.");
    msgBox.exec();

    }
    }

    When the condition is if(event->key() == Qt::Key_Down )
    and press down key its working but when I try checking focus on the last button its not.
    I set setFocusPolicy(Qt::StrongFocus); in the widget.

    Please help .Thank you.


    Added after 4 minutes:


    Hi ,
    In refresh(), I want to update the text of all the 10 pushbuttons. I want to call this function when the 10th button is reached and then down key is pressed. That is the case I tried to put in the if condition.
    Last edited by AmulyaT; 5th April 2013 at 04:53.

  3. #3
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: How to know whether a pushbutton is highlighted?

    you should use ["code"] and [/"code"] btw, and if it works with out
    Qt Code:
    1. buttons[9]->hasFocus()
    To copy to clipboard, switch view to plain text mode 
    it seems to me like that button isn't getting focus did you try with out that condition? eg
    Qt Code:
    1. if(buttons[9]->hasFocus()){
    2. QMessageBox msg(QMessageBox::Information, "Document", "The document has been modified.");
    3. msg.exec();
    4. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Apr 2013
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to know whether a pushbutton is highlighted?

    Thanks. You are right. It is not getting the focus. But then when I use the arrow keys I see that it is going to that button..it is highlighted. Then which property do we need to use ? Or do we need to explicitly set something ?Can anybody suggest ?


    Thanks.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to know whether a pushbutton is highlighted?

    Quote Originally Posted by AmulyaT View Post
    Hi ,
    In refresh(), I want to update the text of all the 10 pushbuttons. I want to call this function when the 10th button is reached and then down key is pressed. That is the case I tried to put in the if condition.
    But why do you want to do that, it seems a very unusual thing to do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to know whether a pushbutton is highlighted?

    1.
    I am trying to refresh the text on the pushbuttons once the last pushbutton on the screen is reached.
    As Wysota mentioned, Why you want that logic?

    2.Did you tried what wysota said?
    Why don't you just intercept the focus-in event of the button you want?
    Key press event is a costly event, since it will trigger at every key press. But what you need is, do something on the last button focus. So just use focus-in event


    Hope it helps,
    Bala

Similar Threads

  1. Replies: 3
    Last Post: 29th April 2011, 08:54
  2. How to prevent an icon being highlighted?
    By Stobie in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2010, 09:24
  3. Replies: 1
    Last Post: 5th August 2008, 13:53
  4. QomboBox - activated(), highlighted()
    By Salazaar in forum Newbie
    Replies: 10
    Last Post: 14th June 2007, 11:50
  5. Qtreeview selection highlighted problem?
    By thefisher in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2006, 09:50

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.