- 1 Question : I registered the movement of the dialogue and in the style I registered the border (its color and width); how can I make it so that I can move only the upper strip and I click on the area of this strip, my mouse did not jump, but was in the place where I clamped it? And I also have a problem, when dragging a window (depending on which way) my borders disappear, how can I fix it?
- 2 Question : I need a window (not a dialogue) in which I can create an area in which I can draw or insert a picture. Also, how to make it so that when I bring this window into the main area of the program they are connected (something like AdobePhotoshop)
- 3 Question : How to check whether information is entered into a line or not, and if not, the button is not activated (I tried searching, but it doesn’t work for me, or I didn’t write well) and also how to prevent characters and numbers from entering and of course, how to put a limit on the number of letters that can be entered?
PS The code concerns only the dialogue!
PS2. How to make a paragraph here?
PS3. Novice programmer!
Header file:
namespace Ui { class newF; } class newF : public QDialog { Q_OBJECT Q_PROPERTY(QPoint previousPosition READ previousPosition WRITE setPreviousPosition NOTIFY previousPositionChanged) public: explicit newF(QWidget *parent = 0); ~newF(); QPoint previousPosition() const; private: Ui::newF *ui; QPushButton *ok; QLineEdit *name; QPushButton *cls; QPoint m_previousPosition; protected: void paintEvent(QPaintEvent *event); void mouseMoveEvent(QMouseEvent *event); public slots: void setPreviousPosition(QPoint previousPosition); signals: void previousPositionChanged(QPoint previousPosition); private slots: void cancel(){ close(); } void exit(){ close(); } void Ok(); void TextChanged(const QString text){ if(!name->text().isEmpty()) ok->setEnabled (true); } }; Implementation file:
newF::newF(QWidget *parent) : QDialog(parent), ui(new Ui::newF) { ui->setupUi(this); this->setModal(true); this->setWindowFlags(Qt::FramelessWindowHint); this->setStyleSheet(StyleHelper::getQDialogStyleSheet()); QPushButton *close = new QPushButton (this); close->setGeometry(189, 1, 40, 18); close->setStyleSheet("QPushButton {" "image: url(:/images/close.png);" "background-color: #000000;" "border: none;" "}" "QPushButton:hover {" "background-color: red; " "}"); connect(close,SIGNAL(clicked()),this,SLOT(exit())); QLabel *newf = new QLabel("Name:",this); newf->setStyleSheet("QLabel {" "background-color: #363636;" "color: #000000;" "}"); name = new QLineEdit(this); name->text(); name->setStyleSheet("QLineEdit {" "color: #FFFFFF;" "border: 1px double black const;" "};"); newf->setBuddy(name); connect(name, SIGNAL(textChanged(const QString &text)), this, SLOT(TextChanged(const QString &text))); ok = new QPushButton("OK",this); ok->setStyleSheet("QPushButton {" "background-color: #696969;" "border: none;" "}"); ok->setDefault(true); ok->setEnabled(false); connect(ok,&QPushButton::clicked,this,&newF::Ok); QPushButton *cancel = new QPushButton("Cancel",this); cancel->setStyleSheet("QPushButton {" "background-color: #696969;" "border: none;" "}" "QPushButton:hover {" "background-color: #7D7D7D;" "}"); cancel->setGeometry(0, 0, 20, 50); connect(cancel,SIGNAL(clicked()),this,SLOT(cancel())); QHBoxLayout *hb1 = new QHBoxLayout; hb1->addWidget(newf); hb1->addWidget(name); QHBoxLayout *hb = new QHBoxLayout; hb->addWidget(ok); hb->addWidget(cancel); QVBoxLayout *vb = new QVBoxLayout; vb->addLayout(hb1); vb->addLayout(hb); setLayout(vb); } newF::~newF() { delete ui; } void newF::Ok(){ MainArea *mainarea = new MainArea(); mainarea->show(); } void newF::paintEvent(QPaintEvent *event){ Q_UNUSED(event); QPainter painter(this); painter.setPen(QPen(Qt::black, 40, Qt::SolidLine, Qt::FlatCap)); painter.drawLine(0, 0, 230, 0); } QPoint newF::previousPosition() const { return m_previousPosition; } void newF::setPreviousPosition(QPoint previousPosition) { if (m_previousPosition == previousPosition) return; m_previousPosition = previousPosition; emit previousPositionChanged(previousPosition); } void newF::mouseMoveEvent(QMouseEvent *event) { auto dx = event->x() - m_previousPosition.x(); auto dy = event->y() - m_previousPosition.y(); setGeometry(x() + dx, y() + dy, width(), height()); return QWidget::mouseMoveEvent(event); } PS4. And I would like to know how normal the article is to fill in, so that the code would not look so awful (sorry!)