[완료][QT/Embedded] QString의 문자열의 갯수말고 전체 linewidth를 얻을 수 있는 방법이 있을가요?

resonancme의 이미지

QString에 한글과 숫자를 혼용해서 넣었다고 한다면 한글의 크기와 숫자의 크기가 다르잖아요?

만약 이상태로 라벨에 출력하면 문자열의 갯수보다는 전체 바이트 또는 linewidth가 정해진 크기의

QLabel에 limit가 되지 않을까 생각합니다. 한글로 100개 출력했을때와 숫자로 100개 출력했을때의 전체

길이가 다른것 처럼요. 알 수 있는 방법이 있을까요?

semmal의 이미지

QLabel에 그냥 집어넣으면 디폴트로 길이를 알 수 있지 않나요?

위젯크기만 미리 지정해놓지 않으면 됩니다.

------------------------------
How many legs does a dog have?

klyx의 이미지

'길이'를 정의해주세요. 앞에는 바이트수를 이야기 하시고, 뒤에선 출력했을때의 길이를 이야기 하고 계시네요.

resonancme의 이미지

제가 하려는 것은 마치 인터넷 주소창처럼 어떤 문자열을 QLabel로 출력할 때 문자열의 길이가 QLabel의 크기를 넘어서기 전에 한칸씩 당겨서
출력하려고 합니다. 마치 한칸씩 밀리는 것 처럼요

근데 문자열의 갯수(.length()나 .size()처럼)로는 숫자랑 한글이랑 혼합하였을 때는 밀리는게 불규칙해요;

같은 문자열의 갯수라도 한글로만 이루어져있느냐 숫자로 이루어져있느냐에 따라 QLabel에 출력되는 크기가 다르니까요

이문제를 해결하고 싶어서 질문드렸습니다 ㅜ

klyx의 이미지

실제로 화면에 출력되는 픽셀수를 말씀하시는 거지요?
그거라면 몇가지 방법이 있는데, rich text의 경우는 QTextDocument에 한번 넣어준다음에 확인하는게 좋고, plain text라면 QFontMetrics 클래스를 통해서 할수 있습니다.
다만, 말씀하신 그대로의 목적이라면 이미 만들어져있는 QLineEdit를 이용하시는게 편할 것입니다.

익명 사용자의 이미지

QString theText = "dodododododododododo";
QRect textRect = p.fontMetrics().boundingRect (theText);
qDebug() << "width : " << textRect.width();

익명 사용자의 이미지

감사합니다^^

익명 사용자의 이미지

감사합니다^^

resonancme의 이미지

감사합니다^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.