Project

General

Profile

Actions

Bug #13872

open

WCompositeWidget does not Apply Style classes from Implementation class

Added by Christian Meyer 5 days ago. Updated about 21 hours ago.

Status:
New
Priority:
Normal
Target version:
Start date:
07/28/2025
Due date:
% Done:

0%

Estimated time:

Description

Only Tested with WPanel implementation so far.

Making a WCompositeWidget implement a WPanel, the Panel Specific style classes are not added.

Making it collapsible: it works, but there is no indicator: the Collapse Button is not visible.

It does not even look like a WPanel or "card" at all.

Unless this is desired behaviour, but I do not think so

Sample Code WCompositeWidget


Sample Code WPanel in Contrast


Files

wt_Composite_Impl_Style.patch (1.31 KB) wt_Composite_Impl_Style.patch Patching WCompositeWidget and Bootstrap5Theme for implementation Styles Christian Meyer, 07/28/2025 05:10 PM
wt_Composite_Impl_Style.patch (15.8 KB) wt_Composite_Impl_Style.patch Updated Patch v1 Christian Meyer, 08/01/2025 04:50 PM
Actions #1

Updated by Matthias Van Ceulebroeck 5 days ago

  • Assignee set to Matthias Van Ceulebroeck
  • Target version set to 4.12.3

Hello Christian,

this is a VERY good catch. No theming is ever applied to the WPanel.

This could be the case for any widget that is set as the WCompositeWidget's implementation. I am however sure I have seen this work for certain other widgets, and am curious as to what the discrepancy is.

Actions #2

Updated by Christian Meyer 5 days ago

Hi Matthias

The Wt- Internal Composite Widgets (like WPanel) work as expected. Because they are a Special Type that is handled in the Theme.

It is different for User Generated Composites.

From what I could figure out, I wrote a Patch, but it really is not a longterm, global solution.

It just targets WBootstrap5Theme, making its apply() function a friend of WCompositeWidget, and in the apply() function, change the widget to the implementation() of the composite Widget.

Breaking Solution

Actions #3

Updated by Christian Meyer about 21 hours ago

I made a way better patch...

I added a function to WCompositeWidget to check if the impl_ widget can be cast to a Type:

template <typename T>
bool canCastTo() const {

  if (!impl_) {
    return false; // Cannot cast if no implementation widget exists
  }

  // Perform the dynamic_cast and check if it succeeds
  return dynamic_cast<T>(impl_.get()) != nullptr; 
}

There are concepts for the future, and also static_asserts to make sure the type fits. (left out here)

Within the ::apply() functions of the Bootstrap and Css Theme Classes, I added a check to see if it is a composite:

WCompositeWidget *composite = dynamic_cast<WCompositeWidget*>(widget);

auto panel = dynami_cast<WPanel*>(widget);

if(panel || (composite && composite->canCastTo<WPanel*>()))
{
... // Apply Style
}

Updated the ::apply() Function for WCSSTheme as well as Bootstrap 2, 3 & 5

Actions

Also available in: Atom PDF