Results 1 to 4 of 4

Thread: Clickable area for QPushButton with menu

  1. #1
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Clickable area for QPushButton with menu

    I have a custom widget created in Qt Designer with a QPushButton. In code, I added a menu to the button with setMenu. For some reason, I can only "trigger" the button by clicking the right edge of it, if I click anywhere else (and its a fairly wide button), it does not register. If I click on the very edge, the menu pops up (it seems like I have just a 2-pixel wide area to click). I added a mousePressEvent in the parent widget to see what was happening and when I check for the child widget at the point the mouse was clicked, it does not give me that widget, I can't tell what widget it is (object name = "" so I assume its not a widget I explicitly added in Designer interfering ??) but it seems like there's possibly a widget above it that's interfering? Any suggestions? Even a hack at this point (to explicitly set the clickable area of the button?) as I really need a solution! I'm using layouts so I don't see how I could have an overlapping widget, it seems I must be getting the "background widget" underneath the button when I check the widget at that point. I've read about bugs on Mac OSX related to style sheets but I'm using Windows 7 and I am not using a style sheet on this widget.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clickable area for QPushButton with menu

    1. What is the logic of adding a menu to a button??
    This is probably a very bad design - if you explain what you want to achieve (not what how, but what) we might suggest a better solution for it.
    Read about QAction - it is probably what you need.
    2. Show your code.
    3. Please format your text in paragraphs, its hard to read it in such a big "chunk".
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clickable area for QPushButton with menu

    Of course after I finally posted my question that's been troubling me for days, I think I've found the cause of the problem and, at least, a workaround. Maybe someone can suggest a better solution, but in the meantime, this might be relevant and useful to others.

    My button is at the very top left corner of my widget. After looking closer at the widget returned in mousePressEvent childAt(evt->pos()), I see that the widget being returned is actually an instance of a class that I am using that inherits QWidget in order to make use of winEvent but is not actually explicitly added to my GUI/widget/layout/etc. The class was written by a collegue and I did not even realize it was inheriting QWidget until now. The object is used and apparently its "widget" is automatically placed at the top left position on top of everything else and is invisible. Therefore its taking precedence over my button. I moved my button over to the right and I can click it anywhere I want. So, I need to either move this other widget "under" my button or I guess to an empty location on my GUI or have it ignore mouse events but allow widgets under it to receive mouse events. Any suggestions appreciated.


    high_flyer -

    A button with a menu is a very useful tool!

    I'd show code but I made the widget in Qt Designer and my class that uses the ui has 5000 lines of code and clearly wasn't doing anything to the button other then using "QPushButton::setMenu" so I don't know what piece of code would be relevant.

    Anyways, I found the cause of my problem (above).


    Solution -

    I guess once the problem was found a solution was fairly obvious, I just set the size of the interfering widget to (0,0) (using setFixedSize).

    Hope this is helpful to someone else!
    Last edited by SKolaMunn; 2nd March 2012 at 15:35.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Clickable area for QPushButton with menu

    high_flyer -

    A button with a menu is a very useful tool!

    I'd show code but I made the widget in Qt Designer and my class that uses the ui has 5000 lines of code and clearly wasn't doing anything to the button other then using "QPushButton::setMenu" so I don't know what piece of code would be relevant.
    I admit I haven't seen it before - and indeed it seems Qt does have a QPushButton with a menu.
    I have learned a new thing today too
    Still, personally I don't understand what is the use of it - and in what way it is different then having a context menu called on the button - seems to do the same thing, just with a different user interaction (look) - and only under some styles.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Qpushbutton not clickable but not greyed
    By gab74 in forum Qt Programming
    Replies: 8
    Last Post: 15th December 2011, 12:21
  2. How to exceed mouse area of Qpushbutton
    By vidya.p in forum Newbie
    Replies: 2
    Last Post: 26th November 2011, 04:12
  3. Problem with styled QPushButton clickable area
    By koan in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2011, 22:48
  4. Replies: 3
    Last Post: 8th December 2010, 05:42
  5. TextEdit demos qt item menu not clickable
    By giusepped in forum Qt Programming
    Replies: 2
    Last Post: 1st July 2010, 04:46

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.