Results 1 to 9 of 9

Thread: QLabel with text and icon

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLabel with text and icon

    Hi I would have a QLabel ( to show text in a status bar )
    containing a small icon ( on the left size ) and some text on the right side.
    Is possible ? Or should I create a new widget?
    Best Regards,
    Franco
    Franco Amato

  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: QLabel with text and icon

    Is possible ? Or should I create a new widget?
    Which part of the StatusBar documentation was not clear, that I should explain here?
    Last edited by high_flyer; 26th January 2011 at 19:13. Reason: fixed link to correct class
    ==========================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
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel with text and icon

    Quote Originally Posted by high_flyer View Post
    Which part of the QProgressBar documentation was not clear, that I should explain here?
    I didn't get you.
    Why QProgressBar?
    Franco Amato

  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: QLabel with text and icon

    Sorry I meant StatusBar of course.

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel with text and icon

    Quote Originally Posted by high_flyer View Post
    Sorry I meant StatusBar of course.
    Hi yes.
    I splitted the statusbar in 3 parts. In the first part (0) I would display a text and a small icon and in the other parts I
    would display only text. So I used Qlabel but it can't contain text+icon in the same QLabel or yes?
    Regards
    Last edited by franco.amato; 26th January 2011 at 21:13.
    Franco Amato

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLabel with text and icon

    QLabel displays either an icon or text. You could:
    • Use rich text for the label, e.g: label->setText("<img src=':/icon.png' /> Text of label"), and put the icon into the program resources.
    • Create a QWidget subclass that contains two QLabels in a horizontal layout and exposes a setIcon() and setText() method.
    • Create a custom widget with just-the-way-you-like-it paint() method.

  7. The following user says thank you to ChrisW67 for this useful post:

    franco.amato (26th January 2011)

  8. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel with text and icon

    Quote Originally Posted by ChrisW67 View Post
    QLabel displays either an icon or text, but not both. You could:
    • Use rich text for the label, e.g: label->setText("<img src=':/icon.png' /> Text of label"), and put the icon into the program resources.
    • Create a QWidget subclass that contains two QLabels in a horizontal layout and exposes a setIcon() and setText() method.
    • Create a custom widget with just-the-way-you-like-it paint() method.
    Thank you very much


    Added after 1 10 minutes:


    Hi,
    it works but the size of the icon broke the status bar. How can I force the ico to have a small size?
    Regards
    Last edited by franco.amato; 26th January 2011 at 23:56.
    Franco Amato

  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLabel with text and icon

    Create a smaller icon

    You can also set a height and/or width attribute on the img tag in the rich text option, but you get a scaled image which is often unsatisfying.

  10. The following user says thank you to ChrisW67 for this useful post:

    franco.amato (27th January 2011)

  11. #9
    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: QLabel with text and icon

    "Format c:" also helps
    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.


Similar Threads

  1. QLabel text and ElideMode (...)
    By Talei in forum Newbie
    Replies: 3
    Last Post: 8th May 2010, 19:54
  2. How to right-justify QLabel text
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 09:55
  3. Replies: 2
    Last Post: 14th January 2008, 19:09
  4. Text under the Icon
    By QiT in forum Newbie
    Replies: 3
    Last Post: 1st April 2007, 18:42
  5. Qlabel with (icon and text) HowTo ?
    By QiT in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2006, 09:14

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.