make GUIUtil::ThemedLabel UI form friendly #358

pull jarolrod wants to merge 1 commits into bitcoin-core:master from jarolrod:themedlabel-forms changing 2 files +16 −2
  1. jarolrod commented at 7:59 am on June 7, 2021: member

    This allows the GUIUtil::ThemedLabel class able to be used in UI form files. This is accomplished by introducing a form file friendly constructor which only takes in a QWidget* parent.

    You cannot pass in the platform_style when initializing a GUIUtil::ThemedLabel in a UI form file. This introduces a setPlatformStyle function to be able to pass in the platform_style at a later point.

    Additionally; because we are not initializing the class with a platform_style, we need to implement a check in updateThemedPixmap so that it only executes when the m_platform_style has been set. A segfault would occur without this conditional as a ChangeEvent occurs on application start

    This allows this class to be used in the form file for #330 for an elegant solution.

  2. qt: make GUIUtil::ThemedLabel UI form friendly
    This makes the GUIUtil::ThemedLabel class able to be used in UI form
    files. This is accomplished by introducing a form file friendly
    constructor which only takes in a `QWidget* parent`.
    
    You cannot pass in the `platform_style` when initializing a
    GUIUtil::ThemedLabel in a UI form file. This introduces a
    `setPlatformStyle` function to be able to pass in the `platform_style`
    at a later point.
    
    Additionally; because we are not initializing the class with a
    `platform_style`, we need to implement a check in `updateThemedPixmap`
    to only occur when the `m_platform_style` has been set. A segfault would
    occur without this conditional as a `ChangeEvent` occurs on application
    start
    f923b80a23
  3. hebasto added the label UI on Jun 7, 2021
  4. in src/qt/guiutil.h:249 in f923b80a23
    245     protected:
    246         void changeEvent(QEvent* e) override;
    247 
    248     private:
    249-        const PlatformStyle* m_platform_style;
    250+        const PlatformStyle* m_platform_style = nullptr;
    


    luke-jr commented at 9:16 pm on June 12, 2021:
    {nullptr}
  5. luke-jr changes_requested
  6. hebasto renamed this:
    qt: make GUIUtil::ThemedLabel UI form friendly
    make GUIUtil::ThemedLabel UI form friendly
    on Jun 12, 2021
  7. in src/qt/guiutil.cpp:800 in f923b80a23
    792@@ -793,6 +793,11 @@ qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal m
    793     return font_size;
    794 }
    795 
    796+ThemedLabel::ThemedLabel(QWidget* parent)
    797+{
    798+    QLabel{parent};
    799+}
    800+
    


    hebasto commented at 2:35 am on June 13, 2021:
    0    : QLabel{parent} {}
    
  8. in src/qt/guiutil.cpp:820 in f923b80a23
    811@@ -807,6 +812,11 @@ void ThemedLabel::setThemedPixmap(const QString& image_filename, int width, int
    812     updateThemedPixmap();
    813 }
    814 
    815+void ThemedLabel::setPlatformStyle(const PlatformStyle* platform_style)
    816+{
    817+    m_platform_style = platform_style;
    818+    assert(m_platform_style);
    819+}
    820 void ThemedLabel::changeEvent(QEvent* e)
    


    hebasto commented at 2:43 am on June 13, 2021:
    style nit: Add an empty line as a separator?
  9. hebasto commented at 2:57 am on June 13, 2021: member

    @jarolrod

    I think we should adopt your suggestion on IRC to move the ThemedLabel into its own module for the following reasons:

    Also, it seams reasonable to me to drop this pr, and review both commits in #330, because without actual usage of a promoted widget in a *.ui file it is not easy to test it.

  10. jarolrod commented at 9:52 pm on July 5, 2021: member

    This was meant to be a part of #330. A simpler approach was chosen for that PR and this is no longer worth the effort as the issue has been fixed.

    Note: If there is ever a reason to make the ThemedLabel class UI friendly, the approach should be to do so in its own class file; moving it away from GUIUtil

  11. jarolrod closed this on Jul 5, 2021

  12. bitcoin-core locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/gui. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-23 00:20 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me