Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-12057

<nobr> attribute does the opposite in QToolTip when text contains colon or dash

XMLWordPrintable

      Let's have a simple example:

      #include <QtCore>
      #include <QtGui>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          const QString html = "%1";
          QLabel l;
          l.show();
          QToolTip::showText(QPoint(120,200), html.arg("C:\\path\\to\\some\\c-file.cpp"));
          app.exec();
      }
      

      This shows a QLabel and a QToolTip with the path to a file. Looks nice! (plain.png)
      But wait, what if the path is longer? Line breaks in a file path would look really ugly. To be sure, let's insert HTML's <nobr> attribute:

      #include <QtCore>
      #include <QtGui>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          const QString html = "<nobr>%1</nobr>";
          QLabel l;
          l.show();
          QToolTip::showText(QPoint(120,200), html.arg("C:\\path\\to\\some\\c-file.cpp"));
          app.exec();
      }
      

      But what's this? Now there ARE two line breaks even though the path didn't change at all! (nobr.png)
      Inserting <nobr> leads to line breaks which is the exact opposite of what it should do.

      This obviously has something to do with the colon ( : ) and the dash ( - ). If we replace them, line breaks are gone. Even if they are replaced with white characters!

        1. nobr.png
          2 kB
          Robert Löhning
        2. plain.png
          1 kB
          Robert Löhning
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kkohne Kai Köhne
            rlohning Robert Löhning
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes