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. What is the best widget for implementing messages?
Forum Updated to NodeBB v4.3 + New Features

What is the best widget for implementing messages?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 671 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.
  • T Offline
    T Offline
    Thank You
    wrote on 13 Jun 2021, 16:43 last edited by
    #1

    As said in question what is best widget for implementing messages like messenger or any other application
    7401de98-4797-4eeb-b513-926b4b01211f-image.png

    Don't mind about those creepy shapes but
    It's just design
    I have used QList Widget But
    I can't use STYLESHEETS to design it as I like
    Like different colors in same message

    I can use label but If there is something easy way to do it then It would be easier for me too
    Any suggestions on it?

    Let's make QT free or It will go forever

    TRUE AND FALSE <3

    J 1 Reply Last reply 13 Jun 2021, 17:03
    0
    • T Thank You
      13 Jun 2021, 16:43

      As said in question what is best widget for implementing messages like messenger or any other application
      7401de98-4797-4eeb-b513-926b4b01211f-image.png

      Don't mind about those creepy shapes but
      It's just design
      I have used QList Widget But
      I can't use STYLESHEETS to design it as I like
      Like different colors in same message

      I can use label but If there is something easy way to do it then It would be easier for me too
      Any suggestions on it?

      J Offline
      J Offline
      JonB
      wrote on 13 Jun 2021, 17:03 last edited by
      #2

      @Thank-You
      As you say, you can use QListView for the list support and QLabel would allow rich text like e.g. in-line color change.

      T 1 Reply Last reply 13 Jun 2021, 17:32
      0
      • J JonB
        13 Jun 2021, 17:03

        @Thank-You
        As you say, you can use QListView for the list support and QLabel would allow rich text like e.g. in-line color change.

        T Offline
        T Offline
        Thank You
        wrote on 13 Jun 2021, 17:32 last edited by
        #3

        @JonB So which would consume less memory
        QListWidget or QLabel ??
        Suppose there are 1000 messages
        Then which would be efficient for it

        Let's make QT free or It will go forever

        TRUE AND FALSE <3

        J 1 Reply Last reply 13 Jun 2021, 17:39
        0
        • T Thank You
          13 Jun 2021, 17:32

          @JonB So which would consume less memory
          QListWidget or QLabel ??
          Suppose there are 1000 messages
          Then which would be efficient for it

          J Offline
          J Offline
          JonB
          wrote on 13 Jun 2021, 17:39 last edited by JonB
          #4

          @Thank-You said in What is the best widget for implementing messages?:

          So which would consume less memory
          QListWidget or QLabel ??

          1 QListWidget versus 1 QLabel? How are you going to do your

          Like different colors in same message

          if you use a QListWidget? What do you intend to use other than a QLabel (or maybe QLineEdit, but I don't think so) to display your message texts? Unless you intend to write an item delegate for your messages?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 13 Jun 2021, 19:05 last edited by
            #5

            Hi,

            A thousand labels will always be less efficient than a properly implement model / view architecture.

            There's an excellent Chat Example on the wiki that you can get inspiration from.

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

            T 1 Reply Last reply 14 Jun 2021, 01:54
            2
            • S SGaist
              13 Jun 2021, 19:05

              Hi,

              A thousand labels will always be less efficient than a properly implement model / view architecture.

              There's an excellent Chat Example on the wiki that you can get inspiration from.

              T Offline
              T Offline
              Thank You
              wrote on 14 Jun 2021, 01:54 last edited by Thank You
              #6

              @SGaist Thank you for suggesting

              Sorry I forgot to inform you that
              It isn't real chatting application just like simulated

              All messages are stored in database
              When I clicked the "send message(triangular)" it saves the data to database
              And when I clicked the reload "that circular button" the data re fetches and fill the labels or datas
              Although this isn't real chat application. For now it can do work.

              Now which would be the best Label or Listview/listwidget

              Taking the point that you must update everything when refresh is clicked

              Let's make QT free or It will go forever

              TRUE AND FALSE <3

              J 1 Reply Last reply 14 Jun 2021, 07:49
              0
              • T Thank You
                14 Jun 2021, 01:54

                @SGaist Thank you for suggesting

                Sorry I forgot to inform you that
                It isn't real chatting application just like simulated

                All messages are stored in database
                When I clicked the "send message(triangular)" it saves the data to database
                And when I clicked the reload "that circular button" the data re fetches and fill the labels or datas
                Although this isn't real chat application. For now it can do work.

                Now which would be the best Label or Listview/listwidget

                Taking the point that you must update everything when refresh is clicked

                J Offline
                J Offline
                JonB
                wrote on 14 Jun 2021, 07:49 last edited by
                #7

                @Thank-You
                If you are really concerned about memory and if you really have 1,000 items the only "efficient" way is some kind of model+view with a suitable item delegate for displaying the items. If you want "Like different colors in same message" you probably want some HTML/rich text support.

                T 1 Reply Last reply 14 Jun 2021, 10:34
                0
                • J JonB
                  14 Jun 2021, 07:49

                  @Thank-You
                  If you are really concerned about memory and if you really have 1,000 items the only "efficient" way is some kind of model+view with a suitable item delegate for displaying the items. If you want "Like different colors in same message" you probably want some HTML/rich text support.

                  T Offline
                  T Offline
                  Thank You
                  wrote on 14 Jun 2021, 10:34 last edited by Thank You
                  #8

                  @JonB I think either lineedit with input disabled or QLabel is best for me.
                  Can I insert these in QScrollArea
                  or should I create widget and set layout including all labels??

                      ui->messages->clear();
                      QString command = "SELECT * FROM messages;";
                  
                      {
                          QSqlDatabase db  =  QSqlDatabase::addDatabase("QSQLITE","message_load");
                          db.setDatabaseName("./messages.db");
                  
                  
                          if(db.open()){
                                  QVBoxLayout *messagesLayout = new QVBoxLayout(ui->messageWidget);
                              QSqlQuery query(db);
                              if(query.exec(command)){
                                  while (query.next()) {
                                      QString id = query.value(0).toString();
                                      QString sender = query.value(1).toString();
                                      QString message = query.value(2).toString();
                  QLabel *messageLabel = new QLabel(message+"\n<i style='font-size:7px;'>Sent by: "+sender+"</i>");
                  messagesLayout->addWidget(messageLabel);
                                    
                                  }
                                  ui->messageWidget->setLayout(messagesLayout);
                              }else{
                                 QMessageBox::warning(this,"no","no"+query.lastError().text());
                              }
                  
                          }else{
                              QMessageBox::warning(this,"NO DB ", "NO DB"+db.lastError().text());
                          }
                  
                      }
                  
                  

                  Or can you suggest to add label when button is pressed automatically with scrolling

                  Let's make QT free or It will go forever

                  TRUE AND FALSE <3

                  J 1 Reply Last reply 14 Jun 2021, 10:56
                  0
                  • T Thank You
                    14 Jun 2021, 10:34

                    @JonB I think either lineedit with input disabled or QLabel is best for me.
                    Can I insert these in QScrollArea
                    or should I create widget and set layout including all labels??

                        ui->messages->clear();
                        QString command = "SELECT * FROM messages;";
                    
                        {
                            QSqlDatabase db  =  QSqlDatabase::addDatabase("QSQLITE","message_load");
                            db.setDatabaseName("./messages.db");
                    
                    
                            if(db.open()){
                                    QVBoxLayout *messagesLayout = new QVBoxLayout(ui->messageWidget);
                                QSqlQuery query(db);
                                if(query.exec(command)){
                                    while (query.next()) {
                                        QString id = query.value(0).toString();
                                        QString sender = query.value(1).toString();
                                        QString message = query.value(2).toString();
                    QLabel *messageLabel = new QLabel(message+"\n<i style='font-size:7px;'>Sent by: "+sender+"</i>");
                    messagesLayout->addWidget(messageLabel);
                                      
                                    }
                                    ui->messageWidget->setLayout(messagesLayout);
                                }else{
                                   QMessageBox::warning(this,"no","no"+query.lastError().text());
                                }
                    
                            }else{
                                QMessageBox::warning(this,"NO DB ", "NO DB"+db.lastError().text());
                            }
                    
                        }
                    
                    

                    Or can you suggest to add label when button is pressed automatically with scrolling

                    J Offline
                    J Offline
                    JonB
                    wrote on 14 Jun 2021, 10:56 last edited by
                    #9

                    @Thank-You
                    You asked about memory and efficiency. We have said anything which creates and displays 1,000 widgets will be bad. Yet after your questions you still choose that route.

                    Yes you can put multiple widgets onto a scroll area.

                    1 Reply Last reply
                    3

                    1/9

                    13 Jun 2021, 16:43

                    • Login

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