Results 1 to 2 of 2

Thread: Strange transparent painting behaviour

  1. #1
    Join Date
    Feb 2006
    Location
    Warsaw, Poland
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Strange transparent painting behaviour

    I'm trying to do my own tooltips for my QTreeView, and i've created my own tooltip basing on Qt4 source... I want it to have transparent background becouse in future i want it to have inregular shape image background (or standard rectangle bg). So atm i'm trying to draw standard rectangle bg but transparent (simply dont paint background just content). Here is some code

    Qt Code:
    1. void rosterWidget::paintToolTip(const QModelIndex &idx, const QPoint &pos, QWidget *w) // JUST SHOW TOOLTIP
    2. {
    3. if(rosterTipLabel::instance && rosterTipLabel::instance->index()==idx)
    4. return;
    5.  
    6. int scr;
    7. if (QApplication::desktop()->isVirtualDesktop())
    8. scr = QApplication::desktop()->screenNumber(pos);
    9. else
    10. scr = QApplication::desktop()->screenNumber(w);
    11.  
    12. QPoint p = pos;
    13. p += QPoint(2,
    14. #ifdef Q_WS_WIN
    15. 24
    16. #else
    17. 16
    18. #endif
    19. );
    20.  
    21. rosterTipLabel *label=new rosterTipLabel(idx,QApplication::desktop()->screen(scr));
    22. label->move(p);
    23. label->show();
    24. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. rosterTipLabel::rosterTipLabel(const QModelIndex &index,QWidget *parent): QLabel(parent, Qt::ToolTip)
    2. {
    3. delete instance;
    4. instance=this;
    5.  
    6. setAutoFillBackground(TRUE);
    7. setFrameStyle(QFrame::NoFrame);
    8. setAlignment(Qt::AlignLeft);
    9. // setAttribute(Qt::WA_NoSystemBackground); // I WAS TRYING THIS WITH SAME EFFECT AS WA_OpaquePaintEvent
    10. setAttribute(Qt::WA_OpaquePaintEvent);
    11.  
    12. qApp->installEventFilter(this);
    13. hideTimer.start(10000, this);
    14. img=(index.model()->data(index,FotoRole)).value<QImage>();
    15. status=(index.model()->data(index,Qt::DecorationRole)).value<QImage>();
    16. nick=(index.model()->data(index,Qt::DisplayRole)).toString();
    17. descr=(index.model()->data(index,DescriptionRole)).toString();
    18. idx=index;
    19.  
    20. QPalette pal( QColor(255,255,220,255) /*windowText*/,
    21. QColor(255,255,220,255) /*button*/,
    22. QColor(255,255,220,255) /*light*/,
    23. QColor(255,255,220,255) /*dark*/,
    24. QColor(255,255,220,255) /*mid*/,
    25. QColor(255,255,220,255) /*text*/,
    26. QColor(255,255,220,255) /*bright_text*/,
    27. QColor(255,255,220,255)/*base*/,
    28. QColor(255,255,220,255)/*window*/);
    29.  
    30. qDebug()<<(pal.window()).isOpaque(); //always prints true
    31.  
    32. setPalette(pal);
    33. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void rosterTipLabel::paintEvent(QPaintEvent *e)
    2. {
    3. QPainter painter(this);
    4. painter.setBackgroundMode(Qt::TransparentMode);
    5. //SIMPLE PNG IMAGE JUST A SHAPE WITH NO BACKGROUND
    6. }
    To copy to clipboard, switch view to plain text mode 

    In thumbnail it seems that it is a bit transparent (becouse as a background i can see part of my screen). With code i posted background for my tip paints whole black... I have no more ideas what to do... I've read http://doc.trolltech.com/qq/qq16-background.html but i think i didn't understand it well

    //EDIT
    I forgot to add that im using Qt 4.1.1 version
    Attached Images Attached Images
    • File Type: png s.png (42.8 KB, 37 views)
    Last edited by naresh; 21st March 2006 at 20:54.

  2. #2
    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: Strange transparent painting behaviour

    You should use QWidget::setMask() to tell the paint engine which parts of the widget should be visible.

Similar Threads

  1. Strange xml behaviour when opening the file.
    By cbarmpar in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2008, 20:44
  2. qinputdialog strange behaviour
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2008, 19:29
  3. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  4. Replies: 1
    Last Post: 26th February 2006, 05:52
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

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.