Important: Please read the Qt Code of Conduct -

How to move text in QLabel?

  • Hi,

    I have long text in QLabel, which has width smaller than his text. Of course I don't see full text. For example if my text is "abcdefghij" I can only see in this QLabel "abc" and a half of letter "d". I would like to see other parts for example "bcd", so I would like to move text in QLabel. Is it possible?

  • @TomNow99
    I don't think so. You can play about with moving/scrolling in a QLineEdit, even a read-only one, but for a Qlabel I don't see how you could say "only starting displaying it from the second character onward", or similar. I think you would be responsible for changing the text to start from bcd instead of from abcd to achieve what you ask for.

    You could try reading through It's not the same as you want, but food for thought. You could probably borrow the idea of altering what it is you draw/paint from the label. But all a bit complex.

    Or, as I said, you might change over to a read-only but not disabled QLineEdit, which would allow user to scroll through the text manually. Or, you could implement a "marquee" QLineEdit so it constantly scrolls through its content for the user, but that's a different matter :)

  • @JonB Thank you.

    I find a strange solution to move text in QLabel - move a QLabel and have other QLabels, which will hidden that QLabel with text.

    My code:

        timer = new QTimer;
        connect(timer, SIGNAL(timeout()),this,SLOT(timeoutSlot()));
        text = new QLabel(this);
        labelLeft = new QLabel(this);
        labelRight = new QLabel(this);
        labelLeft->setStyleSheet("QLabel {background:rgb(240,240,240)}");
        labelRight->setStyleSheet("QLabel {background:rgb(240,240,240)}");
        text->setText("Random text, which will be display and move");

    and timeoutSlot:

    void MainWindow::timeoutSlot()
        int tmpPositionX = text->pos().x();

    Do you know better solution?

  • Lifetime Qt Champion


    There's a stack overflow thread about implementing a marquee which might be of interest.

Log in to reply