Results 1 to 7 of 7

Thread: Alternative to QWidget's "Promote to" feature?

  1. #1
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Alternative to QWidget's "Promote to" feature?

    Hi Forum,

    I'm having this weird problem with my color picker that I will eventually use to control RGB LEDs. I found a color wheel (see link) for my project that I wanted to connect to my palette so that when I change the color wheel's current color, the palette will display that color (updatePalette is called from the color wheel's MouseMoveEvent function). But this only works when the color wheel is given its own window (using show() in main). Whenever I try using the QWidget's "Promote to" feature, the program instantly crashes when I move the color wheel cursor.

    You can check out the attached pictures for further understanding. But I'm mostly interested in hearing if there are alternative ways to add this color wheel to my UI without having it as a separate window or without using the QWidget's "Promote to" feature?

    Color wheel with colorwheel.cpp and colorwheel.h:
    https://forum.qt.io/topic/19261/colorwheel

    //Leutzig
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Alternative to QWidget's "Promote to" feature?

    Your code and the code for colorwheel don't match.
    The wheel widget has a constructor with only one argument, you are calling it with two.

    So maybe you made a modification and you are calling the working constructor while the promote widget functionality calls the other one.

    An alternative to the promote widget approach is to just have an empty widget in the UI and use it as a container/parent for the widget you then create in code.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Leutzig (1st November 2015)

  4. #3
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Alternative to QWidget's "Promote to" feature?

    Thanks for the reply,

    Yes, I made a modification in the constructor to call the updatePalette with the color wheel color.

    So in order to use an empty widget as a parent for the colorwheel, I have created a pointer to the widget and passed it in as a parent when I create an instance of the color wheel.

    QWidget * ColorSelect::getColorWheelWidgetPtr()
    {
    QWidget *colorWheelWidgetPtr = ui->colorWheelWidget;
    return colorWheelWidgetPtr;
    }

    And in my main:
    ColorWheel *colorWheel = new ColorWheel(colorSelect->getColorWheelWidgetPtr(), colorSelect);
    colorWheel->show();

    This kind of works. But now I cannot see the color wheel, only the two cursors very close to each other. But the palette's color changes when I move the cursors so that's good. I'm not sure if the color wheel fills the empty widget right.

    Skærmbillede 2015-11-01 kl. 13.32.02.jpg
    Last edited by Leutzig; 1st November 2015 at 12:33.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Alternative to QWidget's "Promote to" feature?

    Quote Originally Posted by Leutzig View Post
    Yes, I made a modification in the constructor to call the updatePalette with the color wheel color.
    Promote widget calls the constructor that takes only QWidget*, so if you don't have that anymore or it doesn't work after your modification, that could explain the observed behavior.
    Should be easy enough to test creating the widget manually using that constructor instead of the code you posted earlier.

    Quote Originally Posted by Leutzig View Post
    So in order to use an empty widget as a parent for the colorwheel, I have created a pointer to the widget and passed it in as a parent when I create an instance of the color wheel.
    You could also just create color wheel inside the constructor of ColorSelect, but ok.

    Quote Originally Posted by Leutzig View Post
    This kind of works. But now I cannot see the color wheel, only the two cursors very close to each other. But the palette's color changes when I move the cursors so that's good. I'm not sure if the color wheel fills the empty widget right.
    You probably forgot to create a layout for the container or to add the color wheel instance to the layout.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    Leutzig (1st November 2015)

  7. #5
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Alternative to QWidget's "Promote to" feature?

    I didn't create any layout so that might be the issue. I'm not certain on how to create one, but in ColorSelect's constructor I added:

    auto layout = new QVBoxLayout();
    layout->addWidget(ui->colorWheelWidget);

    How and where do I add my instance "colorWheel" to the layout?

    Thanks

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Alternative to QWidget's "Promote to" feature?

    No, I am sure colorWheelWidget is already in a layout, right?
    You need to create a layout inside colorWheelWidget and add the color wheel to that layout.

    Qt Code:
    1. ColorWheel *colorWheel = new ColorWheel(ui->colorWheelWidget);
    2.  
    3. QVBoxLayout *layout = new QVBoxLayout(ui->colorWheelWidget);
    4. layout->setMargins(0);
    5. layout->addWidget(colorWheel);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    Leutzig (1st November 2015)

  10. #7
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Alternative to QWidget's "Promote to" feature?

    Thanks a lot,
    The color wheel is now shown perfectly fine. This is sort of my first application so I haven't really used layouts before.
    But I've constrained the size of the "main widget" so the stuff in it aren't gonna move around.

    //Leutzig

Similar Threads

  1. Replies: 15
    Last Post: 14th March 2013, 22:05
  2. Replies: 3
    Last Post: 2nd October 2012, 10:16
  3. "new" + "delete" a QWidget and its children
    By vkincaid in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2010, 21:51
  4. Add "Check for updates" feature
    By jiveaxe in forum Qt Programming
    Replies: 20
    Last Post: 19th September 2008, 16:39
  5. Using the "pixmap function" feature
    By Michiel in forum Qt Tools
    Replies: 8
    Last Post: 24th May 2007, 14:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.