PDA

View Full Version : Costum dialog not longer working



davidlamhauge
26th November 2019, 15:53
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


#ifndef PENCHOOSER_H
#define PENCHOOSER_H

#include <QColorDialog>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>
#include <QComboBox>
#include <QVBoxLayout>
#include <QGridLayout>

class penChooser : public QDialog
{
Q_OBJECT
public:
explicit penChooser(QDialog *parent = nullptr);

QColorDialog *colordialog;
QLabel *labWidth;
QSpinBox *sbWidth;
QLabel *labPen;
QComboBox *cbPen;
QPushButton *btnExit;
QPushButton *btnChange;
QGridLayout *buttonLayout;
QVBoxLayout *layout;
signals:

public slots:

};

#endif // PENCHOOSER_H

penChooser.cpp


#include "penchooser.h"

penChooser::penChooser(QDialog *parent) :
QDialog(parent)
{

colordialog = new QColorDialog();
colordialog->setOption(QColorDialog::NoButtons);

labWidth = new QLabel(tr("Pen width:"),this);

sbWidth = new QSpinBox(this);
sbWidth->setRange(1,50);
sbWidth->setValue(6);

labPen = new QLabel(tr("Pen type:"),this);

cbPen = new QComboBox(this);
QStringList sl;
sl << tr("Standard") << tr("F5 sketching") << tr("F6 User defined")
<< tr("F7 User defined") << tr("F8 User defined");
cbPen->addItems(sl);

btnExit = new QPushButton(tr("Exit"),this);

btnChange = new QPushButton(tr("Change color"),this);

buttonLayout = new QGridLayout();
buttonLayout->addWidget(labWidth,0,0);
buttonLayout->addWidget(labPen,0,1);
buttonLayout->addWidget(sbWidth,1,0);
buttonLayout->addWidget(cbPen,1,1);
buttonLayout->addWidget(btnExit,2,0);
buttonLayout->addWidget(btnChange,2,1);

layout = new QVBoxLayout();
layout->addWidget(colordialog);
layout->addLayout(buttonLayout);

setLayout(layout);
setWindowTitle(tr("Choose Pen color and width"));

cbPen->setCurrentIndex(cbPen->findText("Pen"));
sbWidth->setFocus();
}

In mainwindow.h you'll find

penChooser *pc;
and in mainwindow.cpp


void MainWindow::penPick()
{
pc = new penChooser();
pc->colordialog->setCurrentColor(sketchPad->penColor());
pc->sbWidth->setValue(sketchPad->penWidth());
pc->cbPen->setCurrentIndex(0);
pc->setModal(true);
connect(pc->btnExit, SIGNAL(clicked()), this, SLOT(cancelPenPick()));
connect(pc->btnChange, SIGNAL(clicked()), this, SLOT(okPenPick()));
pc->show();
}

As said, it worked earlier and used to look like this:
13296

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

Ginsengelf
27th November 2019, 07:01
Hi, what does "doesn't work" mean? The dialog does not look as expected? Or does it not show at all?

Ginsengelf

davidlamhauge
27th November 2019, 13:31
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:
13297
...and it looks like this: (Ubuntu 18.04)
13298

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

ChristianEhrlicher
27th November 2019, 16:51
Looks like the native GTK color picker dialog does not allow embedding.

davidlamhauge
27th November 2019, 17:01
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/

d_stranz
27th November 2019, 21:02
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.

davidlamhauge
27th November 2019, 22:18
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.

davidlamhauge
28th November 2019, 05:22
I had time to test it on Mac this morning, and after setting the option to DontUseNativeDialog, it worked like a charm!
Thanks again!