In any Qt application on KDE when I add a QPushButton in designer and check it's text by:
void MainWindow::on_pushButton_clicked()
{
qDebug()<<ui->pushButton->text();
}
The output is preceded by an & :
&PushButton
This behavior does not exist on Windows. It seems that Qt applications on KDE automatically add shortcuts to all push buttons, which is not desired for me. I should note that the ampersands are not created by designer and you can not see them in the.ui file. Actually when the button is added to a widget, an & is placed somewhere in it's text.
Is it possible to disable automatic mnemonics of a Qt application in anyway?
KDEPlatformTheme plugin responsible for it.
A workaround is to add
[Development]
AutoCheckAccelerators=false
to ~/.config/kdeglobals, which prevents KDE from automatically adding accelerators.
Related bug: https://bugs.kde.org/show_bug.cgi?id=337491
Related
I am using Qt 5.11.1 on Manjaro Linux.
When I open Qt Designer, create a new dialog and add stuff on the widget, Qt Designer adds '&' (ampersand) in the text in some types of widgets automatically. (Ampersand "&" is shortcut in Qt, commonly referred to as "mnemonic". For example, if text of button is "b&utton", I can click the button with Alt + U. See this answer for more information.) For example, if I create a radio button and set the text to "button", the text will become "b&utton" automatically, and I cannot remove the '&'. What should I do?
Not sure, probably qt_set_sequence_auto_mnemonic function is what you are looking for.
Specifies whether mnemonics for menu items, labels, etc., should be honored or not. On Windows and X11, this feature is on by default; on macOS, it is off. When this feature is off (that is, when b is false), QKeySequence::mnemonic() always returns an empty string.
Note: This function is not declared in any of Qt's header files. To use it in your application, declare the function prototype before calling it.
The workaroud in How to disable automatic mnemonics in a Qt application on KDE? works. Thank you Andrii for providing the link!
The workaroud is to add
[Development]
AutoCheckAccelerators=false
to ~/.config/kdeglobals.
I also found that removing the package kdelibs4support is also a workaround, but some packages might depend on it.
Right now I have a small tool app that runs in the icon tray. When I click on the icon, the app goes into "windowstayontophint" mode. I added a Combo Box on this window. But when I click elsewhere on desktop, and then click the combo box, the drop down window goes to the back of the window. This seems to be a known bug as reported here:
https://bugreports.qt.io/browse/QTBUG-61804
Is there a workaround for this? I am using Qt 5.9.1.
EDIT: Add some code:
This in MainWindow constructor:
Qt::WindowFlags flags = this->windowFlags();
this->setWindowFlags(flags|Qt::WindowStaysOnTopHint);
Then I put a QComboBox in the mainwindow with preloaded items. First time click, the dropdown appears on top as normal. Then I click onn desktop and then back on the mainwindow and combobox. And drop down becomes at the back of mainwindow. CLick on the link above to see what I mean. The bug report also provide screenshot of what is happening.
Nobody want to put an answer, so I answer this myself.
ANSWER: Update to latest Qt.
It did not work for me because I was having trouble updating (noob here). What basically happened was that Selecting "Update" option on Maintenance Tool does not update SDK from 5.9.1 to 5.10.1. It only update certain things like Qt Creator.
I needed to choose "Add or remove Components" and then adding Qt 5.10.1, but only check the MinGW 32bit only. (Uncheck all others otherwise you need them (like android or other)).
Even after that, you also need to manually download CMake (get it from cmake.com) and set it in "Manage Kits" in Qt Creator.
How to Hide the Back Button in Qt installer framework?
Please see attached image.
See my answer to Qt installer framework hide or disable buttons quoted below:
For the wizard BackButton specifically, it automatically disables itself if there are no pages before the current page a la the Introduction page.
From QtScript this can be accomplished by removing any dynamic pages before the current page with installer.removeWizardPage and disabling all default pages before the current page with installer.setDefaultPageVisible(QInstaller.Introduction, false).
There is void QWizard::setButton ( WizardButton which, QAbstractButton * button ) what means you schould be able to set a button which behaves like you need it. Derive a Class from QAbstractButton. Reimplement the paintEvent() to paint nothing and reimplement the mouseEvents to do nothing. That should do the (dirty) trick. Even if the wizard sets it to be visible, it won't draw itself and can't digest and mouse actions. Just tested it ... should work for you.
I am a beginner in QT gui c++ programming. i am trying to load a picture on button click using a pushbutton and label.
inside my mainwindow.cpp , i only added the following.
void MainWindow::on_pushButton_clicked()
{
QPixmap pix("C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg");
ui->img_label->setPixmap(pix);
}
. thats all wat i added in the code. program compiles fine but when it runs, it just shows a portion of image instead of showing the full image. can anyone help. Without even adding to the resources,it showed atleast a part of the image.
you can try using PNG - as depending on your Qt version some plugins are needed for JPG. You should also make the pixmap a member of your class.
You can scale your image to specific size something like that:
void MainWindow::on_pushButton_clicked() {
QPixmap pix("C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg");
ui->img_label->setPixmap(pix.scaled(my_width, my_height,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
If you don't want scale, tell us what layout manager do you use?
I can successfully change the color of a QPushButton using setStyleSheet, but because I'm using QT Creator to make the GUI, every time I run qmake and make, the calls to setStyleSheet disappear.
Changing the palette of the button doesn't change its color either.
What's the best way to change to color of the button without having to manually change my ui_window.h file every time I qmake?
Using style sheets is the right way to do, no matter you're using Qt Creator or not.
From what you are describing, it seems you are writing yourself some code into the ui_window.h, which is the wrong way to set the stylesheet.
You can set it in the constructor of your window class, or set it from the GUI editor (Qt Designer) :
double-click on your window.ui in the project tree displayed by Qt Creator.
select your QPushButton in the GUI editor.
locate the styleSheet property in the properties editor.
click on the three dots (...) : this will bring a stylesheet editor.
If you set the stylesheet with the stylesheet editor, nothing will disappear each time you are rebuilding your app.