What is the best widget for implementing messages?
-
As said in question what is best widget for implementing messages like messenger or any other application
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 messageI 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? -
As said in question what is best widget for implementing messages like messenger or any other application
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 messageI 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?@Thank-You
As you say, you can useQListView
for the list support andQLabel
would allow rich text like e.g. in-line color change. -
@Thank-You
As you say, you can useQListView
for the list support andQLabel
would allow rich text like e.g. in-line color change. -
@JonB So which would consume less memory
QListWidget or QLabel ??
Suppose there are 1000 messages
Then which would be efficient for it@Thank-You said in What is the best widget for implementing messages?:
So which would consume less memory
QListWidget or QLabel ??1
QListWidget
versus 1QLabel
? How are you going to do yourLike different colors in same message
if you use a
QListWidget
? What do you intend to use other than aQLabel
(or maybeQLineEdit
, but I don't think so) to display your message texts? Unless you intend to write an item delegate for your messages? -
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.
-
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.
@SGaist Thank you for suggesting
Sorry I forgot to inform you that
It isn't real chatting application just like simulatedAll 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
-
@SGaist Thank you for suggesting
Sorry I forgot to inform you that
It isn't real chatting application just like simulatedAll 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
@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. -
@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.@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
-
@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
@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.