setMinimumWidth and setMaximumWidth not working
-
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.
can someone please help.
-
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.
can someone please help.
@Krpadia123 said in setMinimumWidth and setMaximumWidth not working:
textLabel->setMinimumWidth(100); // Not working
textLabel->setMaximumWidth(400); // Not WorkingThis 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.