[Qt-interest] Problem when using QPainter on child widgets (with some explanantion)

Deepak Angeshwar angeshwar at gmail.com
Wed Jul 29 10:57:31 CEST 2009


My design is as follows

1. A custom widget has been build bu placing a TextEdit on top of a QWidget
-Lets call this BasePriceLabel

2. Another custom eidget has been created by placing a QPushButton on top of
a QWidget
and the BasePriceLabel has been dragged and placed on top of the QPushButton
- Lets call this BasePriceButton (the button and the QtextEdit are of the
same size so the button just sits on top)

3. Now 2 BasePriceButton widgets have been dragged into another QWidget
- This forms the 3rd custom widget called BaseTradeWidget

I am trying to change the BasePriceButton so that the buttons looks
non-rectangular


This is the section of the code in my BasePriceButton class

    public void paintEvent(QPaintEvent event) {

        QPainter painter = new
QPainter(this.ui.buyButton.ui.basePriceLabel.ui.textEdit);
        QPainterPath rounded_rect = new QPainterPath();
        rounded_rect.addRoundRect(1, 1, width() - 2, rect().height() - 2,
25, 25);
        painter.setClipPath(rounded_rect);
        QRegion maskregion = painter.clipRegion();
        setMask(maskregion);
    }


This widget has got a button and I am trying to make the button
non-rectangular by masking it.
QT throws the warning

QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::setClipPath: Painter not active
QPainter::clipRegion: Painter not active


I am under the impression that masking the TextEdit will also automatically
mask the Button that is under the QTextEdit
Can some one clarify how child widgets can be masked using QPainter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090729/4bad7cca/attachment.html 


More information about the Qt-interest-old mailing list