Results 1 to 9 of 9

Thread: Using a QFrame as a color selection indicator

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Using a QFrame as a color selection indicator

    Hello all,

    I'm having a problem with using a QFrame as a color selection indicator. What I'm trying to do is to place a QFrame into my dialog via designer, set its palette's "Window" role to a color (it starts black), then a QPushButton will invoke a QColorDialog::getColor() to change the base color of the QFrame - the idea is to show the picked color on the parent dialog.

    What I'm seeing when I run my application is that the QFrame is not visible (at all), and no matter what I change the color to (the base color is being stored in the invisible frame), I cannot see it.

    Any ideas? I'm using Qt 4.2.2
    Life without passion is death in disguise

  2. #2
    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 a QFrame as a color selection indicator

    Check src/gui/dialogs/qcolordialog.cpp. There are many interesting widgets like QColorShowLabel, QColorPicker and QColSpinBox.
    J-P Nurmi

  3. #3
    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 a QFrame as a color selection indicator

    I have some different widgets for picking colours ready as well For example the two attached.
    Attached Images Attached Images

  4. #4
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Using a QFrame as a color selection indicator

    Hmm... so instead of simply using a simple QFrame so show what color was selected, the "proper" solution is to make a QWidget from scratch? I can do that, but I would have thought things would be a bit simpler than that.

    EDIT: Actually, from what I can tell, those examples subclass QFrame to do what I'm trying to do. I've pretty much done the same thing, but my frames still do not appear at all. I'm running out of ideas. What could make a QFrame appear in designer, but not appear at all when running as an application?

    Here are all the changed variables from my QFrame, and their values:


    geometry = 82, 6, 16, 16
    (x, y, width, and height, respectively)
    size policy = fixed, fixed, 0, 0
    (hSizeType, vSizeType, horizontalStretch and verticalStretch, respectively)
    autoFillBackground = true
    frameShape = QFrame::Panel
    frameShadow = QFrame::Sunken


    EDIT: Now, I have also sub-classed QFrame and promoted my existing frames to custom widgets. The sub-class has a paintEvent() function that fills a rectangle with the given color, and whenever a new color is set the repaint() function gets triggered. Still no dice.
    Last edited by KShots; 19th March 2007 at 23:20.
    Life without passion is death in disguise

  5. #5
    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 a QFrame as a color selection indicator

    There is no "proper" solution here. Your problem is probably that the frame is transparent (meaning that it doesn't listen to the background colour). Try calling "setAutoFillBackground(true)" on your frame. It might just make it work. Also remember about setting a minimum size for the frame or it'll get shrunk to nothing.

  6. #6
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Using a QFrame as a color selection indicator

    Quote Originally Posted by wysota View Post
    There is no "proper" solution here. Your problem is probably that the frame is transparent (meaning that it doesn't listen to the background colour). Try calling "setAutoFillBackground(true)" on your frame. It might just make it work. Also remember about setting a minimum size for the frame or it'll get shrunk to nothing.
    As I showed above, I had the autoFillBackground set to true via designer. I also had the size fixed at 16 pixels for both height and width, but it being shrunk down to nothing does make sense (I can't even see the border of the frame at the moment). I tried setting the size from a 16x16 fixed size to a 16x16 minimum size to no effect as well. Any other ideas?

    EDIT: Toying around with the dialog, I found that if I took out my horizontal spacers, the button now takes up the whole horizontal section of the dialog, going right over the spot that the frame should be. The frame is being shrunk down to nothing.

    EDIT: On the other hand, telling the button to be a fixed size does not make the frame appear, either. It's like designer sees the frame, but the application does not bother building it.
    Last edited by KShots; 20th March 2007 at 02:11.
    Life without passion is death in disguise

  7. #7
    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 a QFrame as a color selection indicator

    Does this work?

    Qt Code:
    1. #include <QApplication>
    2. #include <QFrame>
    3. #include <QWidget>
    4. #include <QLayout>
    5.  
    6. int main(int argc, char **argv){
    7. QApplication app(argc, argv);
    8. QWidget wgt;
    9. QHBoxLayout *l = new QHBoxLayout(&wgt);
    10. QFrame *f = new QFrame;
    11. QPalette p = f->palette();
    12. p.setColor(QPalette::Window, Qt::red);
    13. p.setColor(QPalette::Base, Qt::blue);
    14. p.setColor(QPalette::Button, Qt::green);
    15. f->setPalette(p);
    16. f->setAutoFillBackground(true);
    17. l->addWidget(f);
    18. wgt.show();
    19. wgt.resize(300, 200);
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

    Which style do you use for your applications? I checked the above code with Plastique and Cleanlooks and they both worked fine (red frame background).

  8. #8
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Using a QFrame as a color selection indicator

    I think what's going on is that if you have an expanding object in your layout, your empty QFrame disappears to nothingness.

    I've tried setting minimum, base, and fixed sizes for the QFrame to no avail. Maybe if I put a simple label inside or something as a test case
    Life without passion is death in disguise

  9. #9
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 3 Times in 3 Posts

    Default Re: Using a QFrame as a color selection indicator

    One thing I can tell you is happening is that the properties you have seen and applied in qt designer dont appear at run time. In my case, I had manual code to set the stylesheet of my qframe subclass to give it a background color. This made it visible by showing the background. On the other hand the frame is not visible even if I try to set it programatically which brought me to this forum. Also, the subclassed qframes I had instantiated without setting the background color using stylesheet appear invisible to me as well.

Similar Threads

  1. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

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.