Results 1 to 8 of 8

Thread: Costum dialog not longer working

  1. #1
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Costum dialog not longer working

    I worked on a drawing software in 2012-13, but haven't touched it since. Now I'm brushing it up, and it works fine, except a costum dialog that doesn't work anymore.
    Many things can have changed, but my search has so far been without result.
    Here's the header and cpp-file:

    penChooser.h

    Qt Code:
    1. #ifndef PENCHOOSER_H
    2. #define PENCHOOSER_H
    3.  
    4. #include <QColorDialog>
    5. #include <QLabel>
    6. #include <QPushButton>
    7. #include <QSpinBox>
    8. #include <QComboBox>
    9. #include <QVBoxLayout>
    10. #include <QGridLayout>
    11.  
    12. class penChooser : public QDialog
    13. {
    14. Q_OBJECT
    15. public:
    16. explicit penChooser(QDialog *parent = nullptr);
    17.  
    18. QColorDialog *colordialog;
    19. QLabel *labWidth;
    20. QSpinBox *sbWidth;
    21. QLabel *labPen;
    22. QComboBox *cbPen;
    23. QPushButton *btnExit;
    24. QPushButton *btnChange;
    25. QGridLayout *buttonLayout;
    26. QVBoxLayout *layout;
    27. signals:
    28.  
    29. public slots:
    30.  
    31. };
    32.  
    33. #endif // PENCHOOSER_H
    To copy to clipboard, switch view to plain text mode 
    penChooser.cpp

    Qt Code:
    1. #include "penchooser.h"
    2.  
    3. penChooser::penChooser(QDialog *parent) :
    4. QDialog(parent)
    5. {
    6.  
    7. colordialog = new QColorDialog();
    8. colordialog->setOption(QColorDialog::NoButtons);
    9.  
    10. labWidth = new QLabel(tr("Pen width:"),this);
    11.  
    12. sbWidth = new QSpinBox(this);
    13. sbWidth->setRange(1,50);
    14. sbWidth->setValue(6);
    15.  
    16. labPen = new QLabel(tr("Pen type:"),this);
    17.  
    18. cbPen = new QComboBox(this);
    19. sl << tr("Standard") << tr("F5 sketching") << tr("F6 User defined")
    20. << tr("F7 User defined") << tr("F8 User defined");
    21. cbPen->addItems(sl);
    22.  
    23. btnExit = new QPushButton(tr("Exit"),this);
    24.  
    25. btnChange = new QPushButton(tr("Change color"),this);
    26.  
    27. buttonLayout = new QGridLayout();
    28. buttonLayout->addWidget(labWidth,0,0);
    29. buttonLayout->addWidget(labPen,0,1);
    30. buttonLayout->addWidget(sbWidth,1,0);
    31. buttonLayout->addWidget(cbPen,1,1);
    32. buttonLayout->addWidget(btnExit,2,0);
    33. buttonLayout->addWidget(btnChange,2,1);
    34.  
    35. layout = new QVBoxLayout();
    36. layout->addWidget(colordialog);
    37. layout->addLayout(buttonLayout);
    38.  
    39. setLayout(layout);
    40. setWindowTitle(tr("Choose Pen color and width"));
    41.  
    42. cbPen->setCurrentIndex(cbPen->findText("Pen"));
    43. sbWidth->setFocus();
    44. }
    To copy to clipboard, switch view to plain text mode 
    In mainwindow.h you'll find
    Qt Code:
    1. penChooser *pc;
    To copy to clipboard, switch view to plain text mode 
    and in mainwindow.cpp
    Qt Code:
    1. void MainWindow::penPick()
    2. {
    3. pc = new penChooser();
    4. pc->colordialog->setCurrentColor(sketchPad->penColor());
    5. pc->sbWidth->setValue(sketchPad->penWidth());
    6. pc->cbPen->setCurrentIndex(0);
    7. pc->setModal(true);
    8. connect(pc->btnExit, SIGNAL(clicked()), this, SLOT(cancelPenPick()));
    9. connect(pc->btnChange, SIGNAL(clicked()), this, SLOT(okPenPick()));
    10. pc->show();
    11. }
    To copy to clipboard, switch view to plain text mode 
    As said, it worked earlier and used to look like this:
    penChooser.jpg

    Anyone out there, that can tell me what I'm missing?

  2. #2
    Join Date
    Jul 2008
    Posts
    416
    Thanks
    9
    Thanked 54 Times in 52 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Costum dialog not longer working

    Hi, what does "doesn't work" mean? The dialog does not look as expected? Or does it not show at all?

    Ginsengelf

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

    davidlamhauge (27th November 2019)

  4. #3
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Costum dialog not longer working

    Quote Originally Posted by Ginsengelf View Post
    Hi, what does "doesn't work" mean? The dialog does not look as expected? Or does it not show at all?

    Ginsengelf
    Sorry, It should look this:
    choosePen.png
    ...and it looks like this: (Ubuntu 18.04)
    penchooser_2019Ubuntu.png

    The image in my first post is from Linux (Ubuntu), while the two above is from Windows and Ubuntu..
    It works as expected in Windows (I just found out), but I rarely use Windows myself, and it has a different look in Linux.
    I'll upload it's current look in Linux later, when I get home from work. (Done!)
    David
    Last edited by davidlamhauge; 27th November 2019 at 15:57.

  5. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    459
    Thanked 63 Times in 59 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Costum dialog not longer working

    Looks like the native GTK color picker dialog does not allow embedding.

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

    davidlamhauge (27th November 2019)

  7. #5
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Costum dialog not longer working

    Can that change over time?
    The image in my first post is from Ubuntu. it is taken from my sourceforge account https://sourceforge.net/projects/dastoryboard/

  8. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,193
    Thanks
    236
    Thanked 667 Times in 657 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Costum dialog not longer working

    Can that change over time?
    I presume your original code was based on Qt4 if it was from 2012-3, and that you are trying to rebuild using Qt5. There were huge changes to the underlying implementation of Qt graphics between 4 and 5, even though the outward-facing UI had few changes. I agree with Christian - QColorDialog is a QDialog-based class, and generally dialogs are not designed to be embedded as child widgets in another QWidget- or QDialog-based parent. This is particularly true if the dialog is implemented as a native OS-dependent dialog and not one provided by Qt.

    You might try changing the Qt::WindowFlags for the QColorDialog after you create it (but before it is shown) to remove the Qt::Dialog bit from the flags. You could also try setting the QColorDialog::ColorDialogOption to QColorDialog::DontUseNativeDialog. Don't know if either of these will work, but worth a try.

    And please, if you have learned anything about encapsulation and data hiding since 2012, rewrite your code so none of the UI variable are public and you use signals and slots to communicate changes in your dialog to the rest of your program.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    davidlamhauge (27th November 2019)

  10. #7
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Costum dialog not longer working

    Thank you for the suggestions. I haven't got time to test it now. I'l give feedback when I've tested it.
    I'm selftaught in C++ and Qt, but I've learnt a lot the last year. My plan is to get the software to work again, and then refactor it, because it is a messy bunch of spaghetti-code, with loooong functions, and not much thought on modularization and encapsulation.

  11. #8
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Costum dialog not longer working

    I had time to test it on Mac this morning, and after setting the option to DontUseNativeDialog, it worked like a charm!
    Thanks again!

Similar Threads

  1. App no longer working after upgrade to Qt 5.5.1
    By mut in forum Installation and Deployment
    Replies: 3
    Last Post: 16th March 2016, 09:44
  2. Replies: 0
    Last Post: 13th February 2016, 08:51
  3. costum QWidget with border-image in style sheet
    By qt fan in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2009, 21:36
  4. qDebug() no longer working
    By Doug Broadwell in forum Qt Programming
    Replies: 2
    Last Post: 23rd May 2007, 00:35
  5. can't get a simple dialog working
    By pthomas in forum Newbie
    Replies: 8
    Last Post: 13th January 2006, 15:52

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.