Customizing the QColorDialog for transparency in percentage



  • In QColorDialog, I can control the transparency by giving the option ShowAlphaChannel and change the alpha from 0 to 255. I'd like to control the transparency in terms of percentage. Is there an easy way to change the QColorDialog just so that the alpha channel / transparency control to be in %? Thanks.


  • Moderators

    @Pauly 128 is 50% of 255.
    So, just calculate the alpha from percentage.



  • @jsulm

    Yes, I know that. I just want to replace the alpha value of 0~255 to the percentage, in terms of the GUI input method. Can I do it without dramatic effort like rebuilding the reset of QColorDialog?


  • Moderators

    @Pauly What does "GUI input method" mean?
    What does "rebuilding the reset of QColorDialog" mean?
    Can you explain better what you want to do? Do you want the user to control the transparency?



  • @jsulm

    In the QColorDialog, the transparency is set by entering a value (0~255) to alpha channel input. I would like to let user enter a percentage instead. I understand I can build my own widget to do anything I want, but since I'm ok with all other functions in QColorDialog except just the alpha channel entering, building a new widget for just that seems to be a lot of effort for minimum return.

    I wonder if anyone knows a way to alter the alpha channel input so that it takes the percentage instead of value.


  • Moderators

    @Pauly As far as I can see there is nothing like this in QColorDialog. Most probably you will need to write that by yourself.


  • Qt Champions 2016

    @Pauly
    Hi
    In theory , if using non native dialogs ( so its widgets), you might
    be able to grab the the slider and input field and handle the % thing
    Look into
    QPushButton* button = dialog->findChild<QPushButton*>("Button name");
    ( replace button with edit type / slider type)

    That might allow it in a very hackish way.

    For anything besides a for fun project, its not a good solution to hack the existing dialogs.



  • @mrjj said in Customizing the QColorDialog for transparency in percentage:

    ght allow it in a very hackish

    This sounds like a good idea. What is wrong with it?

    BTW, how could I find the name of the button/edit box etc without the source code?



  • @mrjj

    hmmm. So I try to do this to find out the spin box I want to hack in QColorDialog,

    QColorDialog *newDialog=new QColorDialog();
    QList<QSpinBox *> widgets = newDialog->findChildren<QSpinBox *>();
    for (int i=0; i<widgets.size();i++) { qDebug()<<widgets[i]->objectName();}
    

    and I get:
    ""
    ""
    ""
    ""
    ""
    ""
    ""

    no name??? How would it work or am I missing something?



  • @Pauly
    take a look at the code

    the Spinbox is created without an object name so, no luck there.

    You could iterate over all children of the dialog, and qobect_castthem into QColSpinBox its most likly the last one in the list...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.