Results 1 to 9 of 9

Thread: Qpushbutton not clickable but not greyed

  1. #1
    Join Date
    Sep 2011
    Posts
    51
    Thanks
    2
    Qt products
    Qt4

    Default Qpushbutton not clickable but not greyed

    Hi,
    i need a QPushbutton not clickable but not greyed as disabled...

    Is there a way to reach this result ?

    The button text must remain not greyed.
    The background not greyed...

    Thanks

  2. #2
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton not clickable but not greyed

    Subclass QPushButton and reimplement mousePressEvent.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qpushbutton not clickable but not greyed

    you could do it with an event filter as well.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton not clickable but not greyed

    i need a QPushbutton not clickable but not greyed as disabled...
    Sounds more like a label right ? You could use a label with pushbutton image as background.
    Or you can go as suggested above.. subclass QPushButton and reimplement mousepressevent and ignore it.

  5. #5
    Join Date
    Sep 2011
    Posts
    51
    Thanks
    2
    Qt products
    Qt4

    Default Re: Qpushbutton not clickable but not greyed

    Thanks to all...at the moment i've no code,
    my apps need 2 buttons, when it starts i want only one disabled, but i need that the style of disabled button is the same of the enabled button, so no greyed....as setEnabled(false) property do.
    I need only that one button is unclickable...

  6. #6
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qpushbutton not clickable but not greyed

    use Stylesheets and set a style to QPushButton without explicitly specifying QPushButton[enabled=false]

  7. #7
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qpushbutton not clickable but not greyed

    I would question your design.

    Why you need a button that looks like enabled but it isn't?

    One thing you'll get for sure is user confusion.

  8. #8
    Join Date
    Sep 2011
    Posts
    51
    Thanks
    2
    Qt products
    Qt4

    Default Re: Qpushbutton not clickable but not greyed

    Yes you are right !! But this button will work like a led GREEN/RED. And the only widget to make a like led is a QPushButton...!!!
    A QLineEdit is flat so i think a QPUSHButton is the best solution...

  9. #9
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qpushbutton not clickable but not greyed

    I still think you need to re-think your design.
    You need a button which is not a button, but looks like a button but it fact is a label...

    Read what you're saying - the idea of a button is that it can be interacted with. You're looking for something that will not be interacted with.

    What about QLabel? That's exacly what it is for.

    You can style the label as you want, even to look like a PushButton (I still fail to see a reason for that).

    Qt Code:
    1. QLabel* l = new QLabel("Test", this);
    2. l->setAlignment( Qt::AlignCenter );
    3. l->setStyleSheet(
    4. "QLabel {"
    5. "margin: 1px;"
    6. "border-color: #0c457e;"
    7. "border-style: outset;"
    8. "border-radius: 3px;"
    9. "border-width: 1px;"
    10. "color: black;"
    11. "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #EBEBEB, stop: 1 #CCCCCC );"
    12. "}"
    13. );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problem with styled QPushButton clickable area
    By koan in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2011, 22:48
  2. QLabel clickable
    By bnilsson in forum Newbie
    Replies: 3
    Last Post: 29th July 2009, 08:50
  3. Clickable Regions
    By bbdaffy in forum Qt Programming
    Replies: 6
    Last Post: 22nd July 2009, 11:26
  4. Clickable weblink
    By bnilsson in forum Qt Programming
    Replies: 6
    Last Post: 23rd June 2009, 17:13
  5. Clickable text?
    By hkvm in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2008, 21:49

Tags for this Thread

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.