Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. when i write text on QLineEdit that text shows on QLabel
Forum Updated to NodeBB v4.3 + New Features

when i write text on QLineEdit that text shows on QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 6 Posters 3.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dimple
    wrote on last edited by
    #5

    0_1547636824629_ui.PNG
    on ui page i took QListWidget ,,,on qlist widget i placed QPushbutton ,QLineEdit & QLabel

    can u pls send correct code ??

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #6

      Do you want a button and a label for each element in your list or just 1?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dimple
        wrote on last edited by
        #7

        Thanks for ur reply,,
        No need pushbutton ,,,only QLineEdit & QLabel,,,when i text anything on QLineEdit that text should shows on QLabel thatsit ,,,

        already when i clicked on QPushButton ,,,QLineEdit is showing ,,after write some text on QLineEdit that text should shows on Qlabel

        mrjjM 1 Reply Last reply
        0
        • D Dimple

          Thanks for ur reply,,
          No need pushbutton ,,,only QLineEdit & QLabel,,,when i text anything on QLineEdit that text should shows on QLabel thatsit ,,,

          already when i clicked on QPushButton ,,,QLineEdit is showing ,,after write some text on QLineEdit that text should shows on Qlabel

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #8

          @Dimple
          Hi
          and what does the QListWidget do ?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dimple
            wrote on last edited by
            #9

            After input some text in edittext, QLabel will be changed with this text in QListWidgetItem.

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #10

              Do you want to add items to the list?
              Should the button enable the editing of existing items?
              Do you really need the button (QListWidget by default does what you want on existing items)?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dimple
                wrote on last edited by Dimple
                #11

                -> yes ,, i want to add items to the list .
                ->i want to add some sample datas(EX: Hi ,,hello,,999,,22...etc)
                just for testing

                Actually the goal we must to do is adding and updating contacts in contacts listwidget.

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #12

                  ok, delete your label, lineedit, and pushbutton. try putting in your constructor

                  ui->listwidget->model()->insertRows(0,10);
                  

                  Now there should be 10 blank "labels" in your list widget, if you doubleclick on them a lineedit appears to let you change it and when you move away it goes back into "label mode". All 100% already managed by QListWidget. Is this what you were looking for?

                  Actually the goal we must to do is adding and updating contacts in contacts listwidget.

                  To add a new line you have 2 options:

                  • a button that adds a new line
                  • a system that creates a "ghost line" at the end that, when edited will become a real line (more or less like MS Access lets you change tables)

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  4
                  • D Offline
                    D Offline
                    Dimple
                    wrote on last edited by Dimple
                    #13

                    suppose if i type 1 it shows on qlistwidget ,,
                    next i ll type 2 then on QListWidget shows in order one by one
                    ex: 1
                    2

                    when i type then only it should display in order one by one ,,this is i wanted ???

                    1 Reply Last reply
                    0
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #14

                      I'm not sure I understand the question, sorry...

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      JonBJ 1 Reply Last reply
                      1
                      • VRoninV VRonin

                        I'm not sure I understand the question, sorry...

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #15

                        @VRonin
                        There's some sort of "history" mechanism going on here. The user types something somewhere, it is to be added to this list as the first item. User then types something again, this gets added as the next item in the list.... :)

                        So to the OP, @Dimple: you need to write code so that after each text entered in the line edit it should insert/append one additional row, setting that row's text from the line edit.

                        1 Reply Last reply
                        2
                        • D Offline
                          D Offline
                          Dimple
                          wrote on last edited by
                          #16

                          @VRonin : its ok

                          @JonB : thanks for ur reply ,,im a fresher ,,,can u please if u have a code share with me ??

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #17

                            Hi,

                            Did you took a look at the the example code in QListWidget's documentation ? It shows how to add new items.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              Dimple
                              wrote on last edited by
                              #18

                              @SGaist
                              yes ,,,i added this code now whatever i text ,,,everything is adding in list in order but i want to make it whatever i text ,,that text shows first ??
                              void MainWindow::on_add_clicked()
                              {
                              QString text=ui->lineEdit->text();
                              QListWidgetItem * item = new QListWidgetItem(text);
                              item->setFlags(item->flags() | Qt::ItemIsEditable);
                              ui->listWidget->addItem(item);
                              ui->lineEdit->clear();
                              }

                              mrjjM 1 Reply Last reply
                              0
                              • D Dimple

                                @SGaist
                                yes ,,,i added this code now whatever i text ,,,everything is adding in list in order but i want to make it whatever i text ,,that text shows first ??
                                void MainWindow::on_add_clicked()
                                {
                                QString text=ui->lineEdit->text();
                                QListWidgetItem * item = new QListWidgetItem(text);
                                item->setFlags(item->flags() | Qt::ItemIsEditable);
                                ui->listWidget->addItem(item);
                                ui->lineEdit->clear();
                                }

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #19

                                @Dimple
                                Hi
                                There are in the order you addItem them.
                                However, there is also
                                http://doc.qt.io/qt-5/qlistwidget.html#insertItem
                                which allows you to insert at any row you want and hence put on top if you wish.

                                1 Reply Last reply
                                2
                                • D Offline
                                  D Offline
                                  Dimple
                                  wrote on last edited by
                                  #20

                                  @mrjj thanks for ur reply & thank u all ,,,
                                  i changed two lines of code,,,now whatever i text ,,that is showing first ,,,this is i wanted anyway thanku all for ur reply ,,i got output wat i wanted!

                                  Mainwindow.cpp

                                  #include "mainwindow.h"
                                  #include "ui_mainwindow.h"

                                  MainWindow::MainWindow(QWidget *parent) :
                                  QMainWindow(parent),
                                  ui(new Ui::MainWindow)
                                  {
                                  ui->setupUi(this);
                                  }

                                  MainWindow::~MainWindow()
                                  {
                                  delete ui;
                                  }

                                  void MainWindow::on_add_clicked()
                                  {

                                  QString text=ui->lineEdit->text();
                                  QListWidgetItem * item = new QListWidgetItem(text);
                                  item->setFlags(item->flags() | Qt::ItemIsEditable);
                                  int row = ui->listWidget->row(ui->listWidget->currentItem());
                                  
                                  ui->listWidget->insertItem(row, item);
                                  
                                  
                                   ui->lineEdit->clear();
                                  

                                  }

                                  void MainWindow::on_delete_2_clicked()
                                  {
                                  delete ui->listWidget->currentItem();
                                  }

                                  Ui Page

                                  0_1547799303419_111.PNG

                                  1 Reply Last reply
                                  1

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved