Results 1 to 5 of 5

Thread: correctly embed QColorDialog in QWidget

  1. #1
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default correctly embed QColorDialog in QWidget

    Hi,

    I am trying to embed QColorDialog in a QWidget. After I add the QColorDialog, it shows up correctly, but the layouting doesn't work correctly.
    When I stretch the QWidget by dragging from the bottom right corner, the QColorDialog doesn't occupy the entire resized QWidget. It only stays in the center.
    The minimal code to reproduce this is as follows:

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QColorDialog>
    4. #include <QHBoxLayout>
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. QWidget *w = new QWidget(nullptr);
    9.  
    10. QColorDialog *cDialog = new QColorDialog(w);
    11. cDialog->setWindowFlags(Qt::Widget);
    12. cDialog->setOptions(QColorDialog::DontUseNativeDialog
    13. | QColorDialog::NoButtons);
    14.  
    15. QHBoxLayout *hl = new QHBoxLayout(w);
    16. hl->addWidget(cDialog);
    17. w->setLayout(hl);
    18.  
    19. w->show();
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

    If I replace the QColorDialog with QFontDialog, this works correctly. Please see the attached screenshot that shows the issue
    Capture-QColorDialog_in_QWidget.jpg

    Can anyone help me fix the issue?

    Thanks,
    Ashish

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: correctly embed QColorDialog in QWidget

    What is the resize behavior of the dialog content when you use the dialog directly?
    Maybe its layout is such that the content stays centered.

    Checking the code it has a fixed size.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: correctly embed QColorDialog in QWidget

    Indeed, it has a fixed size constraint.
    Any hints on how to achieve resizing without having to rewrite the entire class again?

    Thanks,
    Ashish

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: correctly embed QColorDialog in QWidget

    I would try unsetting the size constraint of the dialog's layout(), i.e. either setting it to QLayout::SetNoConstraint or QLayout::SetDefaultConstraint

    Cheers,
    _

  5. #5
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: correctly embed QColorDialog in QWidget

    Unfortunately, both SetNoConstraint and SetDefaultConstraint do not work. Please see the attached screenshot. There is a spacer in the original dialog that creates the problem.
    Capture-QColorDialog_DefaultSizeConstraint.jpg

    Thanks,
    Ashish

Similar Threads

  1. How to embed PPT in Qwidget
    By mouni in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2016, 16:51
  2. How to embed WordViewer in qwidget
    By mouni in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2016, 16:15
  3. Is there a way to embed QWidget into a browser?
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2014, 22:25
  4. QAxServer. How to embed QWidget into .NET forrm?
    By ivigasin in forum Qt Programming
    Replies: 3
    Last Post: 29th November 2012, 10:42
  5. Embed QColorDialog as a widget
    By totem in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2010, 00:40

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.