Reputation: 17
I'm building gui for address ip and broadcast address calculator. And i have 3 objects in my mainwindow.ui - textEdit (you type your ip address into it), textEdit_2 (you type your subnet mask address into it), plainTextEdit (just a welcome box). This is my mainwindow.cpp.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
QString users_mask;
QString users_ip;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setStyleSheet("background-color: #484848;");
ui->textEdit->setStyleSheet("border: 1px solid white; color: gray;");
ui->textEdit->setPlainText("Enter ip address");
ui->textEdit_2->setPlainText("Enter mask address here");
ui->textEdit_2->setStyleSheet("border: 1px solid white; color: gray;");
ui->plainTextEdit->setPlainText("Welcome to the ip address calculator!");
ui->plainTextEdit->setStyleSheet("border: 1px #484848; color: #FFFFFF;");
ui->plainTextEdit->setEnabled(false);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::get(){
users_ip = ui->textEdit->toPlainText();
users_mask = ui->textEdit_2->toPlainText();
}
void MainWindow::on_calculate_clicked()
{
get();
qDebug()<<users_ip<<" -- "<<users_mask;
}
now i want the textEdit and textEdit_2 to be cleared whenever a user type something. and is there a function or smth that will allow doing that?
Upvotes: 0
Views: 421
Reputation: 98485
You're looking for the placeholderText
property, but you're using the wrong widget :) Use QLineEdit
instead for those address inputs. placeholderText
is the hint you want shown before user begins their input.
QTextEdit
is a widget meant for general multi-line text editing, and what you're trying to do is a single-line input.
You should also give the widgets self-descriptive names. Instead of having to write textEdit (you type your ip address into it) you could just name that widget ipAddress
and you wouldn't need to explain anything to anyone (much less yourself in a couple months of not looking at the code).
Upvotes: 1