Simplest possible scrollable text box (C++)
-
Very simple requirements:
Add plain ASCII text to box
Allow scrolling with scrollbars if number of lines or columns exceeds displayed area"Would also be nice" (but not imperative):
Capture text to clipboard via mouse-click-drag-highlight
Print all text in textboxThe former is really the main thing, as I'm really just using this as a status display. I don't need editing. I thought there would be a simple Qt example somewhere...?
PS: I'm still running into the infamous 'connection bug' when trying to access this forum via some machines.
Browser and OS are the same (Chrome, Win7) -
@StringTheory
Hi,
can you check if QTextEdit is suitable ?#include <QApplication> #include <QTextEdit> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTextEdit *txt = new QTextEdit(); txt->setText("Hello, world!"); for(int i(0);i<100;i++){ txt->append(QString("adding line : %1").arg(i)); } txt->show(); return a.exec(); }
-
Hi
A simple version would be to place
QScrollArea + layout + QLabel
and for QLabel sets its Text interaction to allow mouse text selection.-
Add plain ASCII text to box
setText will handle that -
Allow scrolling with scrollbars if number of lines or columns exceeds displayed area
QScrollArea handles that -
Capture text to clipboard via mouse-click-drag-highlight
TextInteraction flags allows text to be selected. you have to right click and select copy to go to clipboard. -
Print all text in textbox
that you have to do by hand with QPrinter and friends.
http://doc.qt.io/qt-5/printing.html
-
-
Two excellent replies. I'll try them and get back if there are any remaining questions.
Thanks!(And for some reason, I didn't get the connection bug popup from my main machine this time ("Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.")