Results 1 to 5 of 5

Thread: Designing the display content of a push button

  1. #1
    Join Date
    Apr 2009
    Posts
    21
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Designing the display content of a push button

    I'm using Qt 4.5, the description of QPushButton says: "Push buttons display a textual label, and optionally a small icon."

    However I need more than just a label and an icon. I'd like to have a small number on the top left corner of the button, then in the middle I want to have an icon, then a label, then another icon. I know I can do this with Gtk by setting the button to be a container type and I can pretty much put anything in the button I want. Is there a way for me to do this in Qt? I can't seem to find it

    Any pointer would be greatly appreciated!

  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: Designing the display content of a push button

    You can place any widget inside any other widget in Qt (so to say each widget in Qt is implicitly a container) but it's better if you subclass the button and reimplement its paintEvent() to have a specialized class doing exactly what you want to achieve. Especially that only adding a number in the corner will be faster through subclassing that through composition. The class will have a total of about 10 lines of code and you can reuse it many times.
    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. The following user says thank you to wysota for this useful post:

    cookie1909 (15th April 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    21
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Designing the display content of a push button

    Thanks a lot for your reply. I will try it out. Just wondering, can I add more widgets to the button using Qt Designer?
    Last edited by cookie1909; 15th April 2009 at 21:16.

  5. #4
    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: Designing the display content of a push button

    No, Designer needs widgets to be explicitly marked as containers to allow such things. The regular usecase is that you don't want primitive widgets to be containters so it would only make it harder to use Designer if your widgets would pop up with wrong parents.
    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. The following user says thank you to wysota for this useful post:

    cookie1909 (16th April 2009)

  7. #5
    Join Date
    Apr 2009
    Posts
    21
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Designing the display content of a push button

    Great, thank you! I got it to work with some coding, like you said, 10 lines of code

Similar Threads

  1. problem in Displaying image on push button
    By durgarao in forum Qt Tools
    Replies: 4
    Last Post: 2nd January 2009, 10:27
  2. Line edit and push button
    By dela in forum Newbie
    Replies: 1
    Last Post: 10th December 2008, 16:10
  3. shape of push button
    By Seema Rao in forum Qt Programming
    Replies: 23
    Last Post: 2nd April 2008, 01:05
  4. Push Button problem!!
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2006, 16:31
  5. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40

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.