Results 1 to 9 of 9

Thread: QLabel with text and icon

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    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 18: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
    694
    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
    694
    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 20: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)

Similar Threads

  1. QLabel text and ElideMode (...)
    By Talei in forum Newbie
    Replies: 3
    Last Post: 8th May 2010, 18:54
  2. How to right-justify QLabel text
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 08:55
  3. Replies: 2
    Last Post: 14th January 2008, 18:09
  4. Text under the Icon
    By QiT in forum Newbie
    Replies: 3
    Last Post: 1st April 2007, 17:42
  5. Qlabel with (icon and text) HowTo ?
    By QiT in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2006, 08: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
  •  
Qt is a trademark of The Qt Company.