Results 1 to 20 of 24

Thread: Promoting QLabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Promoting QLabel

    this may be very simple project, I have to work harder.

  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 anafor2004 View Post
    this may be very simple project, I have to work harder.
    I have getting the another way;
    label->setText("<hr>"+label->text());
    but by this you can not specify the coordinates.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

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

    Default Re: Promoting QLabel

    Guys... Try this please:

    Qt Code:
    1. QFont f = label->font();
    2. f.setStrikeOut(true);
    3. label->setFont(f);
    4. label->setText("xxxxx");
    To copy to clipboard, switch view to plain text mode 
    Is that what you want?

  4. #4
    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 wysota View Post
    Guys... Try this please:

    Qt Code:
    1. QFont f = label->font();
    2. f.setStrikeOut(true);
    3. label->setFont(f);
    4. label->setText("xxxxx");
    To copy to clipboard, switch view to plain text mode 
    Is that what you want?
    Dear Sir!
    The above code StrikeOut the text of QLabel. I want to draw a line of on any widget's Background. For example I take here QLabel. But I cann't understand why line is not drwan using the paintEvent.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

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

    Default Re: Promoting QLabel

    Maybe it is drawn but then the widget overdraws it with its own paint event routine.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class W : public QTextEdit {
    4. public:
    5. W() : QTextEdit(){}
    6. protected:
    7. void paintEvent(QPaintEvent *e){
    8. QTextEdit::paintEvent(e);
    9. QPainter p(viewport());
    10. QPen pe = p.pen();
    11. pe.setWidth(4);
    12. pe.setColor(Qt::red);
    13. p.setPen(pe);
    14. p.drawLine(rect().topLeft(), rect().bottomRight());
    15. }
    16. };
    17.  
    18. int main(int argc, char **argv){
    19. QApplication app(argc, argv);
    20. W w;
    21. w.show();
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  6. #6
    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

    Qt Code:
    1. void paintEvent ( QPaintEvent * event )
    2. {
    3. QTextEdit::paintEvent(event);
    4. QPainter painter(viewport());
    5. painter.setPen(Qt::blue);
    6. painter.drawLine(rect().topLeft(),rect().bottomRight());
    7. }
    To copy to clipboard, switch view to plain text mode 
    It is working fine. I am forgotten to call viewport() and paintEvent inside paintEvent(). Thanks for your kind help.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

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

    Default Re: Promoting QLabel

    You should have received a warning in the console.

  8. #8
    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 wysota View Post
    You should have received a warning in the console.
    No, At this time I am not receiving any warning.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

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

    Default Re: Promoting QLabel

    If you opened the painter on a wrong object you should have received a warning. Take my code and change "viewport()" to "this", run the application and look at the console.

  10. #10
    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

    Yes, You are saying true in this regard; but I am telling about the below mentioned code.
    Qt Code:
    1. void paintEvent ( QPaintEvent * event )
    2. {
    3. QTextEdit::paintEvent(event);
    4. QPainter painter(viewport());
    5. painter.setPen(Qt::blue);
    6. painter.drawLine(rect().topLeft(),rect().bottomRight());
    7. }
    To copy to clipboard, switch view to plain text mode 
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

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

    Default Re: Promoting QLabel

    You said you "forgot to call viewport()". I understood that you didn't open a painter on it.

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.