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>
{
Q_OBJECT
public:
explicit penChooser
(QDialog *parent
= nullptr
);
signals:
public slots:
};
#endif // 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
To copy to clipboard, switch view to plain text mode
penChooser.cpp
#include "penchooser.h"
penChooser
::penChooser(QDialog *parent
) :{
labWidth
= new QLabel(tr
("Pen width:"),
this);
sbWidth->setRange(1,50);
sbWidth->setValue(6);
labPen
= new QLabel(tr
("Pen type:"),
this);
sl << tr("Standard") << tr("F5 sketching") << tr("F6 User defined")
<< tr("F7 User defined") << tr("F8 User defined");
cbPen->addItems(sl);
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->addWidget(colordialog);
layout->addLayout(buttonLayout);
setLayout(layout);
setWindowTitle(tr("Choose Pen color and width"));
cbPen->setCurrentIndex(cbPen->findText("Pen"));
sbWidth->setFocus();
}
#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();
}
To copy to clipboard, switch view to plain text mode
In mainwindow.h you'll find
penChooser *pc;
penChooser *pc;
To copy to clipboard, switch view to plain text mode
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();
}
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();
}
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?
Bookmarks