1

I for the life of me can't figure out how to do this.

I have two QPlainTextEdits, with word wrapping off.
I fill one using myTextEdit->document()->setPlainText(myText);
Now myTextEdit has a horizontal scroll bar. Now I want my other textEdit to be able to scroll the exact same amount as myTextEdit, despite how many words are in it. How can i set the width within the scroll area of my other text edit to match that of myTextEdit?

I want the document widths to be the same, but myTextEdit->document()->size() has been of no use. Can anyone help?

picklechips
  • 746
  • 2
  • 8
  • 28
  • why do u want to do this –  Jun 22 '16 at 20:26
  • @JosephMalicke maybe he/she is implementing yet another great text comparison software and wants two edit controls always have synchronized scrolling? – mvidelgauz Jun 22 '16 at 20:32
  • 1
    I'm loading in (a lot of) data from an SQL database, and printing it via formatted string to a PlainTextEdit in order for c/p capabilities and just general time efficiency. It could have upwards of 40000 lines, so i'd like a separate textEdit above to act as a header, and should scroll horizontally with the data so the columns stay lined up. – picklechips Jun 23 '16 at 12:33

2 Answers2

1

Assuming you already have a function (SLOT?) called when first text edit is changed:

myOtherTextEdit->horizontalScrollBar()->setMaximum(myFirstTextEdit->horizontalScrollBar()->maximum());
mvidelgauz
  • 2,176
  • 1
  • 16
  • 23
  • maybe to give up with text editor's own scroll bar (hide it) and your own to the layout? – mvidelgauz Jun 23 '16 at 12:36
  • I just did a qDebug() of myFirstTextEdit->horizontalScrollBar()->maximum and it's ouputting 0... Even though there's plenty of room to scroll – picklechips Jun 23 '16 at 12:50
  • 1
    Welp, turns out I just had to do it outside of the constructor... I spent hours with the right code just in the wrong place, ¯\\_(ツ)_/¯ – picklechips Jun 23 '16 at 13:01
  • Well, thank you for accepting my answer that wasn't actually helpful in your situation. While I intuitively feel that this may happen I curious to know all details... – mvidelgauz Jun 23 '16 at 13:15
0

Have you tried using signal and slots to link the widget sizes with setFixedSize()?