Composite widget + Stylesheets and a weird bug(?)



  • Hi guys. I'm working on a desktop project with the help of ui designer and we found a very weird behavior of qt.
    We have a composite widget called PagerView (inherited from QWidget). this widget has a horizontal layout in which we place buttons for paging large data.
    Our problem is that we are not able to apply stylesheet to our composite widget. For example, if we assign "background-color:yellow" to PagerView, qt designer reflects the change normally, we see the yellow background. see image bellow
    !http://dl.dropbox.com/u/3055964/qt1.GIF(...)!
    but, in runtime, when I run the project, PagerView widget takes normal appearance (gray color), but buttons which are inside the widget becomes yellow. Looks like stylesheet is overridden by QPushButtons. See picture bellow:
    !http://dl.dropbox.com/u/3055964/qt2.GIF(aaa)!

    I'm scratching my head for several hours, but couldn't figure out what could be the problem. Is it a bug or I'm doing something wrong?
    This is the only code PagerView.cpp contains:
    @void PagerView::refresh()
    {
    QLayoutItem *item;
    while((item = ui->hLayout->takeAt(0))) {
    if(item->widget())
    delete item->widget();
    else if(item->spacerItem())
    delete item->spacerItem();
    }

    if(!m_CurrentPage) ++m_CurrentPage;
    
    if(itemsCount() == 0 || pageSize() == 0) return;
    uint buttonsCount = ceil(static_cast<float>(itemsCount()) / static_cast<float>(pageSize()));
    ui->hLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
    
    if(currentPage() > buttonsCount)
        m_CurrentPage = buttonsCount;
    
    for(uint i = 0; i < buttonsCount; ++i) {
        QPushButton *button = new QPushButton(this);
        button->setText(QString::number(i + 1));
        button->setMinimumWidth(40);
        button->setMaximumHeight(20);
        button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
        button->setAutoExclusive(true);
        button->setCheckable(true);
        if(i == currentPage() - 1)
            button->setChecked(true);
        ui->hLayout->addWidget(button);
        connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
    }
    ui->hLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
    

    }@

    You can download the test project from "here":http://dl.dropbox.com/u/3055964/QTest.zip

    Your help is much appreciated.
    Thanks



  • As far as I know, it work only in KDE.
    You can't change color of button.
    !http://storage9.static.itmages.ru/i/12/0123/h_1327342234_4917416_952609311d.png(123)!



  • I don't want to change button colors. I want to change the color of the container, in this case PagerView, but in runtime, button colors are changed instead of PagerView's. The designer renders the widget correctly, but when I run the program, I get that strange behavior.





  • I already tried Palette, but I had same result. Actually, I mentioned background-color for demonstration purpose only, in real scenario, I want to set background image, which is not possible with palette. Anyway thanks for the answer.



  • =|
    If you want image - just paint it.
    @void PagerView::paintEvent(QPaintEvent *)
    {
    QPainter painter(this);
    QPixmap pix("/path");
    painter.drawPixmap(0,0,pix.wight(),pix.height(),pix);
    }@



  • @RazrFalcon thanks again, I appreciate your help :)
    You are right, that's a solution in my situation and I already did that, but one of the powerful feature of Qt is that one don't need to do low level painting in most cases when we have stylesheets. At least, my designer can't for sure :)
    That's why I reported this (possibly) bug here.
    Thanks again :)



  • Fine :)



  • No reaction from Qt stuff? :|


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.