Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, November 2006
Re: Scrolling text window?


Message 1 in thread

"Mark Thompson" <mark@xxxxxxxxxxxx> wrote in message
news:4547D4BF.2080309@xxxxxxxxxxxxxxx
> Is QTextEdit a bit of overkill? (I don't really need a full-blown
> editor).  Is there some other component that would function better?

Depends on what you're doing.  I use a class derived from QListView to
display
error/log messages on my main screen.  It's for display only so I don't want
editing etc.  I can set a max line count and delete the oldest when the
count is exceeded.  I can also format the text with color so alarms are red,
returns are green for example.


In the ctor I set it like:

setSelectionMode(QAbstractItemView::NoSelection);
QPalette p(palette());
p.setColor(QPalette::Base,Qt::black);
setPalette(p);

Then I have a function to add lines.
(I have code to deal with multiple lines in one
buffer but I left that out)

void DisplayScreen::outText(const QString & buffer, const QColor &Color) {
// ignore empty lines
if(!buffer.length()) return;

setUpdatesEnabled(false);
QListWidgetItem *Item;

// Create a listboxitem with the string, color and width
Item = new QListWidgetItem(buffer);
Item->setTextColor(Color);
Item->setTextAlignment(Qt::AlignVCenter);
addItem(Item);

// keep track to remove lines above max limit
int numlines = count() ;
if(numlines > MaxLines) {
delete takeItem(0);

//setCurrentItem(Item);
setCurrentRow(count() - 1);
setItemSelected(currentItem(),false);
setUpdatesEnabled(true);
}


HTH

--
 [ signature omitted ]