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. Problem in getting proper visibility state of the widget when using Stylesheet
Forum Updated to NodeBB v4.3 + New Features

Problem in getting proper visibility state of the widget when using Stylesheet

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 949 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.
  • K Offline
    K Offline
    kumararajas
    wrote on last edited by
    #1

    Dear Experts,

    I am working on an application where in which the MainWidget (Custom class of QWidget) will be the parent widget of all other widgets.

    I am creating the child widgets named ChildWidget(Custom class of QWidget) dynamically and adding these child widgets into parent's widget's stack in the order which my system impose. (That means stacking order of these child widgets are controlled by my application which is an requirement of my application). Each child widget will have its own visibility state based on the widgets shown on the screen.

    Based on some suggestions given by the experts in the below threads (posted by me), my application is working as expected.

    http://www.qtcentre.org/threads/5660...-child-widgets

    http://www.qtcentre.org/threads/5657...tially-visible

    Earlier I was using QPalette to set the background color of both MainWidget and its child widgets (ChildWidget)

    @
    #include <QtGui/QWidget>
    #include <QtGui/QPalette>

    class MainWidget
    {

    --
    

    private:
    QPalette m_palette;
    };

    class ChildWidget : public QWidget
    {
    public:
    ChildWidget(MainWidget* pParent);


    private:
    QPalette m_palette;
    };

    MainWidget::MainWidget(QWidget* pParent) : QWidget(pParent), m_palette(QPalette())
    {

    m_palette.setColor(QPalette::Background, Qt::white);
    setAutoFillBackground(true);
    setPalette(m_palette);
    }

    ChildWidget::ChildWidget(MainWidget* pParent) : MainWidget(pParent), m_palette(QPalette())
    {

    m_palette.setColor(QPalette::Background, Qt::white);
    setAutoFillBackground(true);
    setPalette(m_palette);
    }
    @

    Note: With our current system design the visibility state of each child widget (Refer to above link on Visibility state) has the dependency on the background-color set on it.

    Now I am planning to create the MainWidget and ChildWidget using Qt Designer and set the background-color for MainWidget using the style sheet.

    Open MainWidget.ui -> Right click on the MainWidget -> Change Stylesheet -> select the back ground color -> apply & say OK -> save MainWidget.ui

    Here are my questions:
    a. Is there a way to apply the common style sheet at the parent widget level (for ex MainWidget) so that it applies all its child widgets of type (ChildWidget) without altering their visibility state?
    b. How do I know that style sheet data is propagated from parent widget to child widgets?

    Thank you,
    Kumar

    --Kumar

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can set the style sheet application wide. After that, it's how you write your style sheet that determines where it will be applied (it also applies to setting the style sheet to the parent widget)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kumararajas
        wrote on last edited by
        #3

        Hi Samuel,

        Thank you for the response. That helps me!

        -- Kumara

        --Kumar

        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