Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11188

QColorDialog will only open native Mac OS dialog once, then reverts to non-native version

    XMLWordPrintable

Details

    • macOS
    • 0ffd973b76470e3636577f6335186b36b96e0b9b e083aede62a23af8330bb572366e79e2f42e0cec

    Description

      The following code demonstrates the problem. Run the main window code in a new project; then click the button. The first time the native Mac OS color dialog will appear. The 2nd time it won't.

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QtGui/QMainWindow>
      
      class QColorDialog;
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          MainWindow(QWidget *parent = 0);
          ~MainWindow();
      
      private Q_SLOTS:
          void openColor();
          void colorDialogFinished(int result);
      
      private:
          QColorDialog *color_dialog;
      };
      
      #endif // MAINWINDOW_H
      
      #include "MainWindow.h"
      #include <QPushButton>
      #include <QVBoxLayout>
      #include <QColorDialog>
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
      {
          QWidget *widget = new QWidget();
          QVBoxLayout *layout = new QVBoxLayout(widget);
          QPushButton *button = new QPushButton("Push Me");
          layout->addWidget(button);
          setCentralWidget(widget);
          connect(button, SIGNAL(clicked()), this, SLOT(openColor()));
      }
      
      MainWindow::~MainWindow()
      {
      
      }
      
      void MainWindow::openColor()
      {
          color_dialog = new QColorDialog();
          color_dialog->setOption(QColorDialog::NoButtons, true);
          connect(color_dialog, SIGNAL(finished(int)), this, SLOT(colorDialogFinished(int)));
          color_dialog->show();
      }
      
      void MainWindow::colorDialogFinished(int result)
      {
          color_dialog->deleteLater();
      }
      

      Attachments

        1. MainWindow.cpp
          0.8 kB
          Chris Meyer
        2. MainWindow.h
          0.4 kB
          Chris Meyer
        3. main.cpp
          0.2 kB
          Bjørn Erik Nilsen
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            cmeyer Chris Meyer
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes