659 control->adjustSize(); |
660 control->adjustSize(); |
660 } |
661 } |
661 } else { |
662 } else { |
662 control->setTextWidth(-1); |
663 control->setTextWidth(-1); |
663 } |
664 } |
664 br = QRect(QPoint(0, 0), control->size().toSize()); |
665 |
|
666 QSizeF controlSize = control->size(); |
|
667 br = QRect(QPoint(0, 0), QSize(qCeil(controlSize.width()), qCeil(controlSize.height()))); |
665 |
668 |
666 // restore state |
669 // restore state |
667 control->setTextWidth(oldTextWidth); |
670 control->setTextWidth(oldTextWidth); |
668 } else { |
671 } else { |
669 // Turn off center alignment in order to avoid rounding errors for centering, |
672 // Turn off center alignment in order to avoid rounding errors for centering, |
779 { |
782 { |
780 Q_D(const QLabel); |
783 Q_D(const QLabel); |
781 return d->textInteractionFlags; |
784 return d->textInteractionFlags; |
782 } |
785 } |
783 |
786 |
|
787 /*! |
|
788 Selects text from position \a start and for \a length characters. |
|
789 |
|
790 \sa selectedText() |
|
791 |
|
792 \bold{Note:} The textInteractionFlags set on the label need to include |
|
793 either TextSelectableByMouse or TextSelectableByKeyboard. |
|
794 |
|
795 \since 4.7 |
|
796 */ |
|
797 void QLabel::setSelection(int start, int length) |
|
798 { |
|
799 Q_D(QLabel); |
|
800 if (d->control) { |
|
801 d->ensureTextPopulated(); |
|
802 QTextCursor cursor = d->control->textCursor(); |
|
803 cursor.setPosition(start); |
|
804 cursor.setPosition(start + length, QTextCursor::KeepAnchor); |
|
805 d->control->setTextCursor(cursor); |
|
806 } |
|
807 } |
|
808 |
|
809 /*! |
|
810 \property QLabel::hasSelectedText |
|
811 \brief whether there is any text selected |
|
812 |
|
813 hasSelectedText() returns true if some or all of the text has been |
|
814 selected by the user; otherwise returns false. |
|
815 |
|
816 By default, this property is false. |
|
817 |
|
818 \sa selectedText() |
|
819 |
|
820 \bold{Note:} The textInteractionFlags set on the label need to include |
|
821 either TextSelectableByMouse or TextSelectableByKeyboard. |
|
822 |
|
823 \since 4.7 |
|
824 */ |
|
825 bool QLabel::hasSelectedText() const |
|
826 { |
|
827 Q_D(const QLabel); |
|
828 if (d->control) |
|
829 return d->control->textCursor().hasSelection(); |
|
830 return false; |
|
831 } |
|
832 |
|
833 /*! |
|
834 \property QLabel::selectedText |
|
835 \brief the selected text |
|
836 |
|
837 If there is no selected text this property's value is |
|
838 an empty string. |
|
839 |
|
840 By default, this property contains an empty string. |
|
841 |
|
842 \sa hasSelectedText() |
|
843 |
|
844 \bold{Note:} The textInteractionFlags set on the label need to include |
|
845 either TextSelectableByMouse or TextSelectableByKeyboard. |
|
846 |
|
847 \since 4.7 |
|
848 */ |
|
849 QString QLabel::selectedText() const |
|
850 { |
|
851 Q_D(const QLabel); |
|
852 if (d->control) |
|
853 return d->control->textCursor().selectedText(); |
|
854 return QString(); |
|
855 } |
|
856 |
|
857 /*! |
|
858 selectionStart() returns the index of the first selected character in the |
|
859 label or -1 if no text is selected. |
|
860 |
|
861 \sa selectedText() |
|
862 |
|
863 \bold{Note:} The textInteractionFlags set on the label need to include |
|
864 either TextSelectableByMouse or TextSelectableByKeyboard. |
|
865 |
|
866 \since 4.7 |
|
867 */ |
|
868 int QLabel::selectionStart() const |
|
869 { |
|
870 Q_D(const QLabel); |
|
871 if (d->control && d->control->textCursor().hasSelection()) |
|
872 return d->control->textCursor().selectionStart(); |
|
873 return -1; |
|
874 } |
|
875 |
784 /*!\reimp |
876 /*!\reimp |
785 */ |
877 */ |
786 QSize QLabel::sizeHint() const |
878 QSize QLabel::sizeHint() const |
787 { |
879 { |
788 Q_D(const QLabel); |
880 Q_D(const QLabel); |