Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The parent Dialog gets closed when I click ok to QColorDialog
Forum Updated to NodeBB v4.3 + New Features

The parent Dialog gets closed when I click ok to QColorDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 995 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I have following code that is using https://github.com/liangqi/qt-solutions/tree/master/qtcolorcombobox/srcand the code for QtColorComboBox is taken from https://github.com/liangqi/qt-solutions/tree/master/qtcolorcombobox/src

    In this case I have Custom Dialog which is using QtColorComboBox . In code of QtColorComboBox there is open More..and clicking on More will be open a QColorDialog and when I click on any color and the press OK of QColorDialog then my parent dialog with title Color Dialog gets closed

    Can some one tell me the fix for this issue

    // set the dialog title
    setWindowTitle("Color Dialog");
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QLabel* nameLabel = new IN_CURRENT_POOL QLabel(tr("Color:"));
    colorCB = new IN_CURRENT_POOL QtColorComboBox(this);
    colorCB->setColorDialogEnabled(true);
    colorCB->setStandardColors();
    colorCB->setCurrentColor(Qt::blue);
    nameLabel->setBuddy(colorCB);

    setButton = new IN_CURRENT_POOL QPushButton("Set", this);
    closeButton = new IN_CURRENT_POOL QPushButton("Close", this);
    setButton->setMaximumWidth(90);
    closeButton->setMaximumWidth(90);

    QGridLayout *gridLayout = new IN_CURRENT_POOL QGridLayout;
    QHBoxLayout * firstHboxLayout = new IN_CURRENT_POOL QHBoxLayout;
    QHBoxLayout * secondHboxLayout = new IN_CURRENT_POOL QHBoxLayout;
    firstHboxLayout->addWidget(nameLabel);
    firstHboxLayout->addWidget(colorCB);
    secondHboxLayout->addWidget(setButton);
    secondHboxLayout->addWidget(closeButton);
    gridLayout->addLayout(firstHboxLayout,0,0);
    gridLayout->addLayout(secondHboxLayout,1,0);
    setLayout(gridLayout);

    // QT connections
    connect(setButton, SIGNAL(clicked()), this, SLOT(setColor()));
    connect(closeButton, SIGNAL(clicked()), this, SLOT(hide())

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on last edited by
      #2

      CustomColorDialog::CustomColorDialog(QWidget* parent)
      :QDialog(parent),d_colorCB(0),d_setButton(0),d_closeButton(0)
      {
      // set the dialog title
      setWindowTitle("Set Color");
      setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

      QLabel* nameLabel = new QLabel(tr("Color:"));
      d_colorCB = new QtColorComboBox(this);
      d_colorCB->setColorDialogEnabled(false);
      d_colorCB->setStandardColors();
      d_colorCB->setCurrentColor(Qt::blue);
      nameLabel->setBuddy(d_colorCB);

      d_setButton = new QPushButton("Set", this);
      d_closeButton = new QPushButton("Close", this);
      d_setButton->setMaximumWidth(90);
      d_closeButton->setMaximumWidth(90);

      QGridLayout *gridLayout = new QGridLayout;
      QHBoxLayout * firstHboxLayout = new QHBoxLayout;
      QHBoxLayout * secondHboxLayout = new QHBoxLayout;
      firstHboxLayout->addWidget(nameLabel);
      firstHboxLayout->addWidget(d_colorCB);
      secondHboxLayout->addWidget(d_setButton);
      secondHboxLayout->addWidget(d_closeButton);
      gridLayout->addLayout(firstHboxLayout,0,0);
      gridLayout->addLayout(secondHboxLayout,1,0);
      setLayout(gridLayout);

      // QT connections
      connect(d_setButton, SIGNAL(clicked()), this, SLOT(setColor()));
      connect(d_closeButton, SIGNAL(clicked()), this, SLOT(hide()));

      }

      The parent dialog is QDialog . can some one help me

      class GQCustomColorDialog: public QDialog
      {
      Q_OBJECT
      public:
      GQCustomColorDialog(QWidget* parent = NULL);
      ~GQCustomColorDialog();
      public slots:
      virtual void setColor() =0;
      protected:
      QtColorComboBox* d_colorCB;
      QPushButton* d_setButton;
      QPushButton* d_closeButton;
      };

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        please also show HOW you open the dialog in mainwinodw

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          GQSetColorDialogForInstView* d_setColorDialog ;
          void myView::setColor()
          {

          if (d_setColorDialog == NULL)  {
            d_setColorDialog = new  GQSetColorDialogForInstView(this);
          }
          
          d_setColorDialog->raise();
          d_setColorDialog->show();
          

          }
          }

          GQSetColorDialogForInstView::GQSetColorDialogForInstView( QWidget* parent)
          :GQCustomColorDialog(parent),d_inst(0),d_instView(sourceView),d_phyView(destView)
          {
          }

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hmm, nothing spring to mind why it should close mainwindow
            Do you get any kind of message in creator console?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved