Results 1 to 6 of 6

Thread: Using <QColorDialog>

  1. #1
    Join Date
    Dec 2007
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Using <QColorDialog>

    Hi all
    I want to use <QColorDialog>
    1)I added #include <QColorDialog>
    2)I saw the function I need
    QColor QColorDialog::getColor ( const QColor & initial = Qt::white, QWidget * parent = 0 ) [static] - in the QColorDialog Class Reference

    3)I wrote QColor color = QColorDialog::getColor(const QColor & initial = Qt::white);

    I get error message :

    expected primary-expression before "const"

    what do I do wrong?
    I am also not dure what is the parent Widget, if I write it under one of the private slots (functions from the menu)

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using <QColorDialog>

    You should pass the variable name not the function signature.
    Qt Code:
    1. QColor color = QColorDialog::getColor(Qt::white);
    To copy to clipboard, switch view to plain text mode 

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

    Gily (26th December 2007)

  4. #3
    Join Date
    Dec 2007
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Using <QColorDialog>

    funny me!! thanks

    another question: how can I debug it and see what color selected?
    if I want to add widget , what is the easiest way to do so? (I took "image viewer ' sample and added few functions)
    I want to add another toolbar, and also another image window. id the best way to include in the main class, or do I better writwe a n ew class?
    thanks

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using <QColorDialog>

    Debug what? The selected colour is assigned to the "color" variable of yours.

  6. #5
    Join Date
    Dec 2007
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using <QColorDialog>

    I know, but I want to do some color manipulation and see the result

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Using <QColorDialog>

    Well, you can always print the color to debug output:
    Qt Code:
    1. #include <QtDebug>
    2. ...
    3. qDebug() << color;
    To copy to clipboard, switch view to plain text mode 
    Or you can fill a widget with the color so you can see it with your own eyes:
    Qt Code:
    1. widget->setStyleSheet(QString("background: %1").arg(color.name()));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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.