Results 1 to 11 of 11

Thread: Qlabel

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qlabel

    Hello anyone,

    I have a question about QLabel in a RichTextDocument.

    I have a label called freesLabel and put a pixmaps on it like this.
    QPixmap eca = (QPixmap(":/images/eca.png");
    QPixmap ecp = (QPixmap(":/images/ecp.png");
    QPixmap erf = (QPixmap(":/images/erf.png");
    freeslabel->setPixmap(eca);
    freeslabel->setPixmap(ecp);
    freeslabel->setPixmap(erf);

    Now i want to put this pixmaps into richtextdocument like this.
    Normally you must type this line
    cursor.insertImage(":/images/eca.png"); or (":/images/ecp.png");
    This works ok. but this i don't want.

    I want to make a choice what at that moment is on the freesLabel.
    I have try
    if ( freesLabel == eca) {
    cursor.insertImage( eca); }
    But this give's a error cannot convert from QPixmap to QLabel.
    How make the right code for this.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlabel

    You can try:
    Qt Code:
    1. if((*freesLabel->pixmap()) == eca )
    2. ...do something
    To copy to clipboard, switch view to plain text mode 

    This may not work, so you will have to compare the two pixmaps by looking at relevant member data, such as size, depth, etc.

    Regards

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qlabel

    if((*freesLabel->pixmap()) == eca )

    This did not work.
    Its give's this error:

    error C2678 binary == no operator found wich takes a left-hand operand of type
    çonst QPixmap' (or there is no acceptable conversion).

    maby other suggestions.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlabel

    Well, this is because QPixmap doesn't have an operator==. I assumed that but I wasn't sure.

    I now looked closer at your code and noticed what you are trying to do, and it can be done easier.
    Qt Code:
    1. cursor.insertImage( freesLabel->pixmap());
    To copy to clipboard, switch view to plain text mode 

    And that is it.

    Regards

  5. #5
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qlabel

    if((*freesLabel->pixmap()) == eca )
    cursor.insertImage(freesLabel->pixmap());
    I have try this piece of code but i have still the same error.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlabel

    But why do you do it like that?
    Use only this:
    Qt Code:
    1. cursor.insertImage(freesLabel->pixmap());
    To copy to clipboard, switch view to plain text mode 
    That line will add the pixmap currently contained by the QLabel( whatever it is, eca, ecb .. ) to the document.

    There is no need for any additional testing.

    Regards

  7. #7
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qlabel

    I have try this piece of code
    cursor.insertImage(freesLabel->pixmap());

    This gives a error like this:
    error C2664 void QTextCursor::insertImage( const TextImageFormat &) cannot convert
    parameter 1 from const QPixmap to const QTextImageFormat &

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlabel

    Well, my bad after all .
    Looks like you have to build a QTextImageFormat.
    You will have to set the name, width and height for the image format.
    The name must be the name of the pixmap the label currently displays.
    So you're back at square one. This can be solved as follows:
    every time you set a different pixmap to the label, also add a dynamic property to it. The dynamic property will hold the name of the image:
    Qt Code:
    1. QPixmap erf = (QPixmap(":/images/erf.png");
    2. freeslabel->setPixmap(erf);
    3. freesLabel->setProperty("imagePath", ":/images/erf.png");
    To copy to clipboard, switch view to plain text mode 

    Now, when you wish to insert the image:
    Qt Code:
    1. imgfmt->setName(freesLabel->property("imagePath").toString());
    2. imgfmt->setWidth(freesLabel->pixmap()->width());
    3. imgfmt->setHeight(freesLabel->pixmap()->height());
    4. cursor.insertImage(imgfmt);
    To copy to clipboard, switch view to plain text mode 


    Hopefully this should work.

    Regards

  9. #9
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qlabel

    Iám newbe,

    Maby a stuppid question where put i the width and height of the pixmap.

    Qt Code:
    1. QPixmap erf = (QPixmap(":/images/erf.png");
    2. freeslabel->setPixmap(erf); // here
    3. freesLabel->setProperty("imagePath", ":/images/erf.png");
    4.  
    5. imgfmt->setName(freesLabel->property(":/images/erf.png").toString());
    6. imgfmt->setWidth(freesLabel->pixmap()->width()); //or here
    7. imgfmt->setHeight(freesLabel->pixmap()->height()); //or here
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qlabel

    Well, I have read the docs more carefully, and you might not need that.
    Only do this when you wish to insert a pixmap:
    Qt Code:
    1. QImage img = freesLabel->pixamp()->toImage();
    2. textDoc->addResource(QTextDocument::ImageResource, QUrl("labelImage"), img);
    3. cursor.insertImage("labelImage");
    To copy to clipboard, switch view to plain text mode 

    This will work just fine if you implement it correctly.
    textDocument is your QTextDocument.

    Regards

  11. #11
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qlabel

    Marcel thanks for your time and answers it works fine now.

Similar Threads

  1. background-image on QLabel does NOT work
    By VireX in forum Newbie
    Replies: 2
    Last Post: 8th June 2007, 20:30
  2. QLabel links?
    By gfunk in forum Qt Programming
    Replies: 3
    Last Post: 23rd December 2006, 00:42
  3. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 03:38
  4. QLineEdit && QLabel
    By eleanor in forum Newbie
    Replies: 16
    Last Post: 12th November 2006, 17:30
  5. QLabel with HTML-style formatting docs?
    By Everall in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2006, 20:01

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.