I'm trying to understand why some icons are displayed correctly and some other not on a HiDPI display
Qt 5.15.2
KDE Plasma 5.23.90
2880 x 1800 display
#include "mainwindow.hpp"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.setWindowTitle("HiDPI test");
w.show();
return a.exec();
}
#include "mainwindow.hpp"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle("HiDPI test");
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QFileDialog>
#include <QMainWindow>
#include <QStandardPaths>
#include <QStatusBar>
#include <QToolBar>
#include <QVBoxLayout>
{
Q_OBJECT
public:
MainWindow
(QWidget *parent
= nullptr
);
private Q_SLOTS:
void settings();
private:
};
#endif
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QFileDialog>
#include <QMainWindow>
#include <QStandardPaths>
#include <QStatusBar>
#include <QToolBar>
#include <QVBoxLayout>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
private Q_SLOTS:
void settings();
private:
QToolBar *tool_bar_;
QAction *add_media_;
QAction *remove_media_;
QAction *get_info_;
QAction *download_medias_;
QAction *settings_action_;
QStatusBar *status_bar_;
};
#endif
To copy to clipboard, switch view to plain text mode
#include "mainwindow.hpp"
MainWindow
::MainWindow(QWidget *parent
){
central_widget->setLayout(layout);
setCentralWidget((central_widget));
add_media_
= new QAction(QIcon::fromTheme("list-add"),
"Add",
this);
remove_media_
= new QAction(QIcon::fromTheme("list-remove"),
"Remove",
this);
get_info_
= new QAction(QIcon::fromTheme("documentinfo"),
"Information",
this);
download_medias_
= new QAction(QIcon::fromTheme("download"),
"Download",
this);
settings_action_
= new QAction(QIcon::fromTheme("settings-configure"),
"Settings",
this);
connect(settings_action_, &QAction::triggered, this, &MainWindow::settings);
tool_bar_->addAction(add_media_);
tool_bar_->addAction(remove_media_);
tool_bar_->addSeparator();
tool_bar_->addAction(get_info_);
tool_bar_->addSeparator();
tool_bar_->addAction(download_medias_);
tool_bar_->addSeparator();
tool_bar_->addAction(settings_action_);
layout->addWidget(tool_bar_);
layout->addWidget(status_bar_);
}
void MainWindow::settings()
{
QStringList download_location
(QStandardPaths
::standardLocations(QStandardPaths
::DownloadLocation));
file_dialog->exec();
}
#include "mainwindow.hpp"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget *central_widget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout;
central_widget->setLayout(layout);
setCentralWidget((central_widget));
status_bar_ = new QStatusBar;
tool_bar_ = new QToolBar;
add_media_ = new QAction(QIcon::fromTheme("list-add"), "Add", this);
remove_media_ = new QAction(QIcon::fromTheme("list-remove"), "Remove", this);
get_info_ = new QAction(QIcon::fromTheme("documentinfo"), "Information", this);
download_medias_ = new QAction(QIcon::fromTheme("download"), "Download", this);
settings_action_ = new QAction(QIcon::fromTheme("settings-configure"), "Settings", this);
connect(settings_action_, &QAction::triggered, this, &MainWindow::settings);
tool_bar_->addAction(add_media_);
tool_bar_->addAction(remove_media_);
tool_bar_->addSeparator();
tool_bar_->addAction(get_info_);
tool_bar_->addSeparator();
tool_bar_->addAction(download_medias_);
tool_bar_->addSeparator();
tool_bar_->addAction(settings_action_);
layout->addWidget(tool_bar_);
layout->addWidget(status_bar_);
}
void MainWindow::settings()
{
QFileDialog *file_dialog(new QFileDialog);
file_dialog->setFileMode(QFileDialog::DirectoryOnly);
QStringList download_location(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation));
file_dialog->exec();
}
To copy to clipboard, switch view to plain text mode
cmake_minimum_required(VERSION 3.5)
project(hidpi_test)
add_compile_options(-Wall -Wextra)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Find Qt5
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED)
add_executable(
${PROJECT_NAME}
mainwindow.hpp
mainwindow.cpp
main.cpp
)
target_link_libraries(
${PROJECT_NAME}
Qt5::Widgets
)
cmake_minimum_required(VERSION 3.5)
project(hidpi_test)
add_compile_options(-Wall -Wextra)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Find Qt5
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED)
add_executable(
${PROJECT_NAME}
mainwindow.hpp
mainwindow.cpp
main.cpp
)
target_link_libraries(
${PROJECT_NAME}
Qt5::Widgets
)
To copy to clipboard, switch view to plain text mode
The + (list-add) and - (list-remove) icons are perfect but the others are pixelated. When opening a QFileDialog the buttons icons (New directory, Ok, Cancel) are pixelated too.
Screenshot_20220205_135455.jpgScreenshot_20220205_135322.png
How can I get all the icons right?
Bookmarks