Results 1 to 10 of 10

Thread: image bleeding

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default image bleeding

    'morning,

    I've got a QLabel with text that pops up when the user mouseOver a button. The problem is: part of an image elsewhere in the application is also showing up in the QLabel. Here's an image that will help explain:

    http://www.beg.utexas.edu/coastal/wrl/del/both.jpg

    In the primary window is a QStackedWidget with 2 widgets: the Introduction Widget (visible in the top half of the linked image) which is currently just a QLabel, and a widget containing a Coin3d scenegraph. The "Introduction" button sets the Stack index to the Introduction widget, and the other buttons on the bottom index the Coin3d widget.

    When the Coin3d widget is active (bottom half of the image), mousing over buttons on the left cause QLabel information text boxes to pop up. The white text is part of the QLabel pop-up; unfortunately: part of the image from the Introduction widget is also present. How to make this stop? I've tried things like setting "hide()" on the information widget when it's not active, but that doesn't work.

    as always, thank you.

  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: image bleeding

    Is the information widget transparent?

    If you have overridden its paint event, than issue a fillRect before drawing the text and fill the background with a color.

    Regards

  3. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: image bleeding

    no, no transparency.

    & I don't *think* I overrode a paint event. This is how I'm drawing the panel:

    Qt Code:
    1. panStack = new QStackedWidget(coinWidget);
    2.  
    3. if(panNUM==0)
    4. {
    5.  
    6. // QPainter *paint = new QPainter;
    7. // paint->fillRect((coinWidget->width() - 160), 10, 150, 300, QBrush(Qt::white));
    8. // panLabel[panNUM]->setAutoFillBackground(true);
    9.  
    10. panLabel[panNUM]->setWordWrap(true);
    11. panStr0 = "Test text to see how much text I can put into a QString.";
    12. panLabel[panNUM]->setPalette(QPalette(QColor(1,1,1)));
    13. panLabel[panNUM]->setText(panStr0);
    14. }
    15.  
    16. panStack->addWidget(panLabel[panNUM]);
    To copy to clipboard, switch view to plain text mode 

    and here's the event filter for testing mouseOver:

    Qt Code:
    1. bool Window::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if( (obj == myButton) && (event->type() == QEvent::HoverEnter) )
    4. {
    5. panStack->setGeometry((coinWidget->width() - 160), 10, 150, 300);
    6. panStack->setCurrentIndex(0);
    7. panStack->show();
    8. return QWidget::eventFilter(obj, event);
    9.  
    10. }
    11. else if( (event->type() == QEvent::HoverLeave) )
    12. {
    13. panStack->hide();
    14. return QWidget::eventFilter(obj, event);
    15. }
    16. else
    17. {
    18. return QWidget::eventFilter(obj, event);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    ...ideas?

  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: image bleeding

    One observation regarding the commented code: you cannot paint a widget outside a paint event. Unless you set a flag to that widgets which explicitly states that it can be painted asynchronously( outside a paint event ).

    As for the information widget, try adjusting its geometry also when you adjust it for the stacked widget. Or add it in a container widget with a horizontal/vertical layout and add this container to the stacked widget.

    In the event filter, why do you always set the stack widget index to 0, no matter what button you hover? Shouldn't be an index based on the current button?

    Regards

  5. #5
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: image bleeding

    Quote Originally Posted by marcel View Post
    As for the information widget, try adjusting its geometry also when you adjust it for the stacked widget. Or add it in a container widget with a horizontal/vertical layout and add this container to the stacked widget.
    i tried these: no success. I used a frame widget for the container; it didn't have an effect. I also adjusted the QLabel and QFrame geometry with the stacked widget- nothing.

    I did, however, see a possible clue: if I barely resize the window, then the unwanted picture disappears from the Info Widget the next time I mouseOver. If I go back to the Introduction page, then go back to the coin3d widget/mouseOver: it reappears... but will then disappear again if I barely resize the window. Is there some way to flush out old image info?

    Quote Originally Posted by marcel View Post
    In the event filter, why do you always set the stack widget index to 0, no matter what button you hover? Shouldn't be an index based on the current button?
    oh yeah, i'm just trying to get it to work with the first button now.

  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: image bleeding

    I don't really know. You shouldn't get any garbage at all in your label. Unless you are doing something wrong...

    I am curious if the label gets any update events...

    The solution that has to work is: subclass QLabel or QWidget(better) and override the paintEvent. There, first fill the background with some color and next draw the text.

    But again, normally, you shouldn't get rubbish. What is the parent of the label? From the code I see it is coinWidget. What is that? Could you switch to main window as parent?

    Another thing: I have seen that you keep the info widgets in an array and you also use a stacked widget.
    My opinion is to lose the stacked widget and stick to the array.
    When the mouse leaves a button then just hide its info widget. When it enters, you show it.
    You could use a QMap<QWidget, QWidget>, where the first param is the button, the second is the info widget for the button.
    Something like:
    Qt Code:
    1. map[hoveredButton]->show().
    To copy to clipboard, switch view to plain text mode 
    A stacked widget could have unpredictable behavior when used like this( floating ). I'm just saying what seems easier to do. It still remains your decision.

    Regards

  7. #7
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: image bleeding

    Quote Originally Posted by marcel View Post
    I don't really know. You shouldn't get any garbage at all in your label. Unless you are doing something wrong...
    that's what i'm worried about

    you're right- lose the Stack. I was using it before I realized I would have to use hide()/show() anyway; it's redundant now. I'll clean this up and take another look. Thanks for your help: somebody is owed a case of beer.

  8. #8
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: image bleeding

    Quote Originally Posted by marcel View Post
    There, first fill the background with some color and next draw the text.
    good tip. Actually,

    Qt Code:
    1. myLabel[0]->setAutoFillBackground(true);
    To copy to clipboard, switch view to plain text mode 

    pretty much did the trick. The ghost-image would still show up in the label's margin (if set to >0), but then I changed "setGeometry()" to "move()" in the event filter--and defined the size of the label when I created them--and this fixed it up.

    there is one other thing i would ask you about, if I hadn't bugged you so much already. I'm setting the label sizes like so:

    Qt Code:
    1. void Window::mkPan()
    2. {
    3. int panNUM_TOT = dafo.get_panNUM_TOT();
    4. for(int panNUM=0; panNUM<panNUM_TOT; panNUM++)
    5. {
    6. panLabel[panNUM] = new QLabel(coinWidget);
    7. panLabel[panNUM]->setMargin(5);
    8. panLabel[panNUM]->setMinimumWidth(150); //here
    9. panLabel[panNUM]->setMinimumHeight( int(dafo.get_panStr(panNUM).length()*.8) ); //here
    10. panLabel[panNUM]->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    11. panLabel[panNUM]->setFrameStyle(QFrame::Panel | QFrame::Sunken); // no effect
    12. panLabel[panNUM]->setPalette(QPalette(QColor(1,1,1)));
    13. panLabel[panNUM]->setWordWrap(true);
    14. panLabel[panNUM]->setAutoFillBackground(true);
    15. panLabel[panNUM]->setText(dafo.get_panStr(panNUM));
    16. panLabel[panNUM]->hide();
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    As you can see, I want the width fixed at 150 for all, and the Height to fit the given text String, but this method isn't optimal: there's not a particular variable (.8, etc) that is optimal. Sometimes too long, other times too short. Better way?

  9. #9
    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: image bleeding

    This should do the trick:
    Qt Code:
    1. #define LBL_FIXED_WIDTH 150 //you should do this if it is always fixed
    2. ...
    3. int height = 0;
    4. QFontMetrics metrics(panLabel[panNum]->font());
    5. int txtWidth = metrics.width(panLabel[panNum]->text());
    6. float factor = float(txtWidth)/LBL_FIXED_WIDTH;
    7. height = int( factor*metrics.height() ) + 1;
    To copy to clipboard, switch view to plain text mode 
    So this is the height you should use.
    Factor is approximately how many text lines the label will have.
    Probably you will have to add some vertical row space in there(probably 2-3 pixels)....

    Regards
    Last edited by marcel; 1st August 2007 at 22:07.

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

    vonCZ (2nd August 2007)

  11. #10
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: image bleeding

    thanks again for your help, Marcel. The QFontMetrics example you provided certainly helped, but with one little problem: depending on how the text wrapped & how many lines of text, I would end up with extra space at the bottom of my QLabel. After (way too much) messing around with it, I finally found this to work perfect:

    Qt Code:
    1. int height = 0;
    2. QFontMetrics myMet(myFont);
    3. QRect myRect;
    4. myRect.setWidth(panWIDTH - (2*panMARGIN)); // panWIDTH=150
    5. height = myMet.boundingRect(myRect, Qt::AlignLeft | Qt::TextWordWrap, myString, 0, 0).height() + (2*panMARGIN);
    To copy to clipboard, switch view to plain text mode 

    figured I would post, in case it helps someone else.

Similar Threads

  1. Explanation to Image Formats
    By sincnarf in forum Qt Programming
    Replies: 13
    Last Post: 6th July 2007, 17:02
  2. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.