Results 1 to 20 of 24

Thread: Promoting QLabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Promoting QLabel

    Quote Originally Posted by ashukla View Post
    Qt Code:
    1. ui.label->setDrawingEnabled(true);
    To copy to clipboard, switch view to plain text mode 
    I am unable to find setDrawingEnabled(). Dear JPN, can you tell me this is a Qt4.3.1 function or self to create. In my case error: ‘class QLabel’ has no member named ‘setDrawingEnabled’. Is this a function of other class?
    I meant that he could write such function himself. All it would do is to enabled/disable the flag which is checked in paintEvent().
    J-P Nurmi

  2. #2
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Promoting QLabel

    Quote Originally Posted by jpn View Post
    I meant that he could write such function himself. All it would do is to enabled/disable the flag which is checked in paintEvent().
    Yes! I have done it previously but not getting the output. Output means line inside a QLabel or QTextEdit using this way.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  3. #3
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Promoting QLabel

    Yes I also done it but it doesnt work!!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Promoting QLabel

    May we see the relevant code?
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Promoting QLabel

    Is this some school/academic task? Why are the two of you dealing with exactly the same problem?

  6. #6
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Promoting QLabel

    I think we even not living same country , I know there are so many new beginner in Qt and people fall with same problems.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Promoting QLabel

    Problems of drawing a line across a label? I didn't know it was that common

  8. #8
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Promoting QLabel

    mylabel.h

    Qt Code:
    1. #ifndef MYLABEL_H
    2. #define MYLABEL_H
    3. #include <QLabel>
    4. class MyLabel : public QLabel
    5. {
    6. Q_OBJECT
    7. public:
    8. MyLabel(QWidget *);
    9. void setDrawflag(bool a);
    10.  
    11. protected:
    12. void paintEvent ( QPaintEvent * event );
    13. private:
    14. bool drawflag;
    15. };
    16. #endif
    To copy to clipboard, switch view to plain text mode 


    mylabel.cpp

    Qt Code:
    1. #include"MyLabel.h"
    2. #include <QPainter>
    3. #include <QLabel>
    4. MyLabel::MyLabel(QWidget *parent)
    5. : QLabel(parent)
    6. {
    7. }
    8. void MyLabel::paintEvent(QPaintEvent *event)
    9. {
    10.  
    11. QPainter painter(this);
    12. if(drawflag==true)
    13. {
    14. QPainter painter(this);
    15. setBackgroundRole(QPalette::Dark);
    16. setAutoFillBackground(true);
    17. painter.setPen(Qt::blue);
    18. painter.drawLine(0,0,401,331);
    19. }
    20. }
    21.  
    22. void MyLabel::setDrawflag(bool a)
    23. {
    24. drawflag=a;
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 25th January 2008 at 09:41. Reason: changed [qtclass] to [code]

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Promoting QLabel

    Could you use the #-button instead of Qt-button for code blocks, thank you. Former is for code blocks, latter is for referencing docs of a Qt class.

    So, what does "doesn't work" mean this time? Apparently you want to initialize the flag to a sane value, but I don't see why shouldn't the line get painted after you set the flag to true. But do you perhaps mean that the label should paint its content too, like text/pixmap/whatever you have set? In this case you would have to call the base class implementation of paintEvent().
    J-P Nurmi

Similar Threads

  1. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 21:15
  2. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  3. QLabel links?
    By gfunk in forum Qt Programming
    Replies: 3
    Last Post: 23rd December 2006, 00:42
  4. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 03:38
  5. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 19:57

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.