Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Composite widget + Stylesheets and a weird bug(?)
Forum Updated to NodeBB v4.3 + New Features

Composite widget + Stylesheets and a weird bug(?)

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Davita
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on last edited by
      #2

      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)!

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Davita
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RazrFalcon
          wrote on last edited by
          #4

          Sorry...
          http://developer.qt.nokia.com/wiki/How_to_Change_the_Background_Color_of_QWidget
          "Using the Palette" works for me

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Davita
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RazrFalcon
              wrote on last edited by
              #6

              =|
              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);
              }@

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Davita
                wrote on last edited by
                #7

                @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 :)

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  RazrFalcon
                  wrote on last edited by
                  #8

                  Fine :)

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Davita
                    wrote on last edited by
                    #9

                    No reaction from Qt stuff? :|

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved