Results 1 to 4 of 4

Thread: How do I paint custom controls & then propagate events?

  1. #1
    Join Date
    Dec 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How do I paint custom controls & then propagate events?

    For example, one widget I am trying to create is a mix of QToolButton and QLineEdit.

    When leaveEvent() occurs, it appears like a QToolButton with the icon/text on the left & the menu-arrow on the right (QToolButton.MenuButtonPopup). When enterEvent() occurs, the left half of the button (icon/text) becomes a QLineEdit, while the right half is still a drop down menu.

    I have been trawling through whatever forums google search brings up, and while I loosely understand how to paint it, how do I connect the events properly? If I paint the QLineEdit, how do I get that part of the custom widget to act and respond like a QLineEdit? (Python preferred, C++ is ok, also an example including the paint event would be even better

    [QComboBox will not work, and definitely the other widgets I'd like to create don't have any approximate equivalent. Also, I know I can build a widget with other simpler widgets, and then mess with the stylesheets to achieve something similar looking... but I know there is an answer to the above, because Qt does it, and it would have better cross-system styling then writing custom stylesheets and trying to figure out what to do to make it exactly the same..]

  2. #2
    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 do I paint custom controls & then propagate events?

    Drawing is done via QStyle API. I suggest you derive your widget from QLineEdit to avoid having to reimplement all its functionality, push the content to the left (by setting content margins) and use QStyle API to draw the drop down indicator. Handle events for the drop down and show a menu when it should be activated.
    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.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I paint custom controls & then propagate events?

    As an approximation you could also try a composite widget, using a QLabel and a QLineEdit in a QStackedWidget on the left half and a button on the right half.

    You then implement enter and leave event such that you trigger which of the two left side widgets is the one visible in the stacked widget.

    Cheers,
    _

  4. #4
    Join Date
    Dec 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I paint custom controls & then propagate events?

    Thanks. Working with these suggestions.

Similar Threads

  1. Replies: 1
    Last Post: 21st March 2012, 13:44
  2. paint events
    By freekill in forum Newbie
    Replies: 3
    Last Post: 18th February 2010, 06:29
  3. Custom controls when QTreeWidgetItem edited.
    By kubas in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2009, 10:27
  4. Propagate mouse events 'physically' rather than 'logically'
    By sebastian.f in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2009, 19:46
  5. Custom shaped forms and controls
    By AlbertGoodwill in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 06:35

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.