Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. setMinimumWidth and setMaximumWidth not working
Qt 6.11 is out! See what's new in the release blog

setMinimumWidth and setMaximumWidth not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 628 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krpadia123
    wrote on last edited by
    #1

    I have label created and want tooltip over it, I want to set tooltip's maximum and minimum width.

    Code snippet

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QListWidget listWidget;
        listWidget.setContentsMargins(QMargins(0, 0, 0, 0));
        QListWidgetItem* item = new QListWidgetItem();
    
        for (int i = 0; i < 5; ++i)
        {
            auto *itemWidget = new QWidget();
    
            auto *textLabel = new QLabel(QString("Item %1").arg(i + 1), itemWidget);
            textLabel->setStyleSheet("QToolTip { color: #E3E3E3; background-color: #383838; border: 0px ; font:15px; background-clip: border;;}");
            textLabel->setMinimumWidth(100); // Not working
            textLabel->setMaximumWidth(400); // Not Working
            textLabel->setToolTip("<p>This is the nakkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk that is longet than </p>");
    
            listWidget.addItem(item);
            listWidget.setItemWidget(item, itemWidget);
        }
    
        listWidget.show();
    
        return a.exec();
    }
    

    Tooltips rename same doesn't matter whatever value I set on them.
    6095d850-c8a4-4508-9d46-581abde9645d-Screenshot (153).png

    can someone please help.

    jsulmJ 1 Reply Last reply
    0
    • K Krpadia123

      I have label created and want tooltip over it, I want to set tooltip's maximum and minimum width.

      Code snippet

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QListWidget listWidget;
          listWidget.setContentsMargins(QMargins(0, 0, 0, 0));
          QListWidgetItem* item = new QListWidgetItem();
      
          for (int i = 0; i < 5; ++i)
          {
              auto *itemWidget = new QWidget();
      
              auto *textLabel = new QLabel(QString("Item %1").arg(i + 1), itemWidget);
              textLabel->setStyleSheet("QToolTip { color: #E3E3E3; background-color: #383838; border: 0px ; font:15px; background-clip: border;;}");
              textLabel->setMinimumWidth(100); // Not working
              textLabel->setMaximumWidth(400); // Not Working
              textLabel->setToolTip("<p>This is the nakkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk that is longet than </p>");
      
              listWidget.addItem(item);
              listWidget.setItemWidget(item, itemWidget);
          }
      
          listWidget.show();
      
          return a.exec();
      }
      

      Tooltips rename same doesn't matter whatever value I set on them.
      6095d850-c8a4-4508-9d46-581abde9645d-Screenshot (153).png

      can someone please help.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Krpadia123 said in setMinimumWidth and setMaximumWidth not working:

      textLabel->setMinimumWidth(100); // Not working
      textLabel->setMaximumWidth(400); // Not Working

      This sets min/max width for the label, it has nothing to do with the tool tip.
      I don't think there is a way to define max/min width for tool tips as those are just strings.
      You can try to insert new line ('\n') in your string when it is is too long to force a line break.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved