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. Simplest possible scrollable text box (C++)
QtWS25 Last Chance

Simplest possible scrollable text box (C++)

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 6.7k Views
  • 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.
  • S Offline
    S Offline
    StringTheory
    wrote on last edited by
    #1

    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 textbox

    The 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)

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @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();
      }
      
      1 Reply Last reply
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        A simple version would be to place
        QScrollArea + layout + QLabel
        and for QLabel sets its Text interaction to allow mouse text selection.

        alt text

        • 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

        1 Reply Last reply
        5
        • S Offline
          S Offline
          StringTheory
          wrote on last edited by
          #4

          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.")

          1 Reply Last reply
          0

          • Login

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