[Qt-interest] Problem customizing QListView

Parta lists4pghanghas at gmail.com
Wed Jun 9 12:44:30 CEST 2010


Hi

I want to draw a custom background and some other overlays for my
custom QListView.
But I am not able to get rid of the white backgound that is default in
Qt-widgets or draw anything of my own.
I tried changing the palette which didnt work.
I tried reimplimenting the paint but that also doesn't work instead it
gives me a
warning while running the application
"QPainter::begin: Widget painting can only begin as a result of a paintEvent"
I dont understand why it gives that warning, as far as I know I am in
the right paintEvent
and trying to draw onto a valid paintDevice.

I also tried making the paintevent opaque by using
"Qt::WA_OpaquePaintEvent". So that Qt doesn't draw anything on its
own.
But even that doesnt have any effect.

I am able to make the widget transparent though by using
setStyleSheet("background: transparent")


Here is the pseudo code with all the methods that I tried to use to
get my own background.

class CustomListView : public QListView
{

public:
    explicit CustomListView(QWidget *parent = 0)
    {
        // these are not required if the QPalette::window or paintEvent work
        // but just to show that I have tried these, I included these lines
        this->setAutoFillBackground(false);
        this->setAttribute(Qt::WA_NoSystemBackground);
        this->setAttribute(Qt::WA_OpaquePaintEvent);
    }

protected:
    virtual void paintEvent(QPaintEvent *e)
    {
        QPainter painter(this);
        painter.fillRect(rect(), QColor(0,0,0,180));
    }
};


main()
{
    QApplication app(argc, argv);

    QPalette pal = app.palette();
    pal.setColor(QPalette::Window, QColor(20,20,20,100));
    app.setPalette(pal);

    CustomListView view;
    view.setGeometry(100,100,200,200);
    view.show();

    return app.exec();
}

Any help will do, I am badly stuck on this one.

--
Thanks in Advance,
Parta



More information about the Qt-interest-old mailing list