I want to set a placeholder text in a QLineEdit. I am using the below code to do so:
QLineEdit *q = new QLineEdit;
q->setPlaceholderText("Enter number");
But on executing, the placeholder does not set. What may be the problem here?
I want to set a placeholder text in a QLineEdit. I am using the below code to do so:
QLineEdit *q = new QLineEdit;
q->setPlaceholderText("Enter number");
But on executing, the placeholder does not set. What may be the problem here?
As the isolated code you have provided is not enough to give us a clue where the problem is, I suggest you to try this minimalistic example, see if it works for you and adapt it for your purpose. If the adaptation does not work, then post the changes you have made to discuss them.
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLineEdit>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QLineEdit *q = new QLineEdit(this);
q->setPlaceholderText("Enter number");
setCentralWidget(q);
}
© 2022 - 2024 — McMap. All rights reserved.
setText()
, the placeholder will disappear, you are sure that you have not done that. With the code you show it is impossible to solve the problem. It would be great to share your complete code through github, drive, etc to review it. – IcarianQLineEdit *q = new QLineEdit(this);
– Kappennethis
is a view. – Bittner