QMessageBox you can select text from

Is there a way to display a QMessageBox that could select text so that the user can use their mouse or keyboard to somehow select and copy its contents? I know that I can create shortcuts that do this, but I'm not sure about the messages. The standard message box in MS Windows certainly does not allow this.

+7
qt
source share
2 answers

I prefer to solve this using a stylesheet.
Run this once and it will affect all message boxes created anywhere in the application:

 qApp->setStyleSheet("QMessageBox { messagebox-text-interaction-flags: 5; }"); 

I tested this with Qt 5.5 for OS X and it works.

+7
source share

You need to enable the TextSelectableByMouse interaction TextSelectableByMouse :

 QMessageBox mb(QMessageBox::NoIcon, "New message", "A lot of text", QMessageBox::Ok, this); mb.setTextInteractionFlags(Qt::TextSelectableByMouse); int dialogResult = mb.exec(); 
+7
source share

All Articles