I want to change the default icon that shows up at the top left corner of the frame.
I have tried many approaches- xpm, ico, bmp,
using SetIcon(wxIcon(wxT("icon.xpm"))); as suggested here.
I tried different icon sizes, 16x16, 24x24 and 32x32.
I've also tried adding MYICON1 ICON "Logo.ico" in the resource.rc file, #define MYICON1 101 in the resource.h file and SetIcon(wxIcon(MYICON1)); to the frame constructor..
btw, i'm using wxwidgets 2.8 on visual studio 2010
EDIT:
I've also tried adding MYICON1 ICON "Logo.ico" in the resource.rc file, #define MYICON1 101 in the resource.h file and SetIcon(wxIcon(MYICON1)); to the frame constructor..
With this approach, I get an error in the wxIcon(int) constructor..
1>xsframe.cpp(17): error C2248: 'wxString::wxString' : cannot access private member declared in class 'wxString'
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\wx/string.h(682) : see declaration of 'wxString::wxString'
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\wx/string.h(659) : see declaration of 'wxString'
PS, xsframe is my main frame. whose icon i'm trying to change.
SetIcon(wxICON(MYICON1));
in file gdicmn.h ,line 166
/* Useful macro for creating icons portably, for example:
wxIcon *icon = new wxICON(sample);
expands into:
wxIcon *icon = new wxIcon("sample"); // On Windows
wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
*/
I am quoting Vaclav's answer from here:
You can set your main frame's icon with wxFrame::SetIcon. Application
icon can be changed by adding a new icon resource to your .rc file:
appicon ICON "myapp.ico"
#include "wx/msw/wx.rc"
Note that this icon must be the first icon in your .rc file and it
must be the first one when you sort your icons alphabetically. This is
because MS developers weren't able to make their mind on how to
determine app's icon: it is the first one in .rc file under Windows 9x
and the alphabetically first one under NT (or vice versa).
Most people usually miss this. Hope that fixes things.
You wrote: MYICON1 ICON "Logo.ico" in the resource.rc file, and SetIcon(wxIcon(MYICON1)); to the frame constructor
That is the approach I use.
There is an extra step you need to do. In the resource.h file you need to define MYICON1 Something like this:
#define MYICON1 101
You have to ensure that the icon file contain ALL the required resolutions - I always ensure it has 16by16, 32by32 AND 256by256 The more the merrier!
It is a good idea if the application icon is the FIRST icon in the resource file.
I recommend upgrading to wxWidgets v2.9.4 - lots of things start working better.
Use the string name of the icon, not the numeric identifier. Look at any wxWidgets sample for an example.
A quick and dirty, non-portable, only-Windows solution (worked for me in Windows 7, wxWidgets 3.0.4, vc110):
#ifdef __WXMSW__
#include "wx/msw/private.h" //for wxGetInstance()
#endif
...
//in Frame's constructor:
HWND hWnd = this->GetHandle();
HINSTANCE hInstance = wxGetInstance();
HICON hIcon = ExtractIcon(hInstance, L"someicon.ico", 0);
SetClassLongPtr(hWnd, GCLP_HICONSM, (LONG_PTR)hIcon);
Could be useful for doing some other tricks on the window?
Related
My solution consists of an MFC App + Static library (name StatLib).
My StatLib contains resources (including icons), included in the "app.rc2" file in this way:
...
#include "C:\Project\LIBS\StatLib\StatLib.rc"
...
like described in this page.
I sort the icon ID's in this way:
App:
#define IDR_MAINFRAME 128
IDR_MAINFRAME ICON "res\MyApp.ico"
StatLib:
#define IDI_EM2D_ICON2 20018
#define IDI_EM2D_ICON3 20019
IDI_EM2D_ICON2 ICON "res\icon2.ico"
IDI_EM2D_ICON3 ICON "res\icon3.ico"
Like described in this page.
The problem is, the compiler automatically assigns to the exe the first icon it finds in the StatLib "icon2.ico" and not "MyApp.ico"
Below a screenshot of my application. I want to get rid of the white spaces after the last tables lines marked by red rectangles :
The horizontal size policy is expanding and the vertical one is minimum and for other tables it is both set to expanding.
I'm using this method I found in another SO question but as you can see the result is not flawless.
void verticalResizeTableViewToContents(QTableView* tableView)
{
tableView->resizeRowsToContents();
// does it work ?
tableView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
int rowTotalHeight = 0;
// Rows height
int count = tableView->verticalHeader()->count();
for (int i = 0; i < count; ++i) {
// 2018-03 edit: only account for row if it is visible
if (!tableView->verticalHeader()->isSectionHidden(i)) {
rowTotalHeight += tableView->verticalHeader()->sectionSize(i);
}
}
// Check for scrollbar visibility
if (!tableView->horizontalScrollBar()->isHidden())
{
rowTotalHeight += tableView->horizontalScrollBar()->height();
}
// Check for header visibility
if (!tableView->horizontalHeader()->isHidden())
{
rowTotalHeight += tableView->horizontalHeader()->height();
}
tableView->setMaximumHeight(rowTotalHeight);
}
Somewhere, I'm using this code to setup one of the tables :
m_Internals->Ui.Measures->setModel(mm->getPh66MeasuresModel());
m_Internals->Ui.Measures->horizontalHeader()->setSectionsMovable(true);
m_Internals->Ui.Measures->horizontalHeader()->setHighlightSections(false);
m_Internals->Ui.Measures->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
m_Internals->Ui.Measures->horizontalHeader()->setStretchLastSection(true);
m_Internals->Ui.Measures->verticalHeader()->hide();
m_Internals->Ui.Measures->setSelectionBehavior(QAbstractItemView::SelectRows);
verticalResizeTableViewToContents(m_Internals->Ui.Measures);
I'm using Qt ModelView pattern to populate/update the tables.
Update : I made a small example to reproduce this issue with QTableView : https://github.com/embeddedmz/QTableViewAdjustPolicyNotWorkingProperly
Using the latest Qt version (from Qt official installer), there's no issue. However, using the Qt library provided by vcpkg (outdated for sure) the issue is there.
With Qt provided by vcpkg :
With the latest Qt provided by the Qt Company (update not the latest, it's 5.12.11) :
If you have something fully buildable on Ubuntu 20.04 LTS, post a link to the complete project (strip it down to just this part) and I will take an actual stab at it.
My gut, having worked with Qt for years, is telling me you are being burned by Margins.
https://doc.qt.io/qt-5/qwidget.html#contentsMargins
You probably need to set a bottom margin of Zero.
https://doc.qt.io/qt-5/qmargins.html#setBottom
If you retrieve the margins for those widgets you will probably find they are non-zero.
you can also fix your problem with one trick, this problem happens for you because your data is lower than the table size. I clone your project and change sizepolicy
Under Qt 5.12.11, the bug does not exist. So I took a look at the QAbstractScrollArea::sizeHint code of this version and compared it with the implementation used in recent versions of Qt and found that setting verticalScrollBarPolicy to "ScrollBarAlwaysOff" the "AdjustToContents" adjustment policy works. The default value was "ScrollBarAsNeeded", in fact we can see that this value is not handled but since in Qt 5.12.11 we only compare the vertical|horizontal]scrollBarPolicy to Qt::ScrollBarAlwaysOn it prevents this bug from appearing.
To clarify, I mean the icon that is displayed when the app is running (e.g. inside the dock).
With trial and error, I found out that it uses "/usr/share/pixmap/xfce4-terminal.xpm" as the icon (tested by replacing this file with some other icon).
I was unable to find where it maps the running xterm to this icon.
If I copy the xterm binary to a different name and run that one, it gets a different icon, which shows that there is a possibility to change it.
I already tried setting the "xterm*iconPixmap:" resource, but that appears to have no effect at all.
You could try using xseticon
usage: xseticon [options] path/to/icon.png
options:
-name : apply icon to the window of the name supplied
-id : apply icon to the window id supplied
Sets the window icon to the specified .png image. The image is loaded from
the file at runtime and sent to the X server; thereafter the file does not
need to exist, and can be deleted/renamed/modified without the X server or
window manager noticing.
If no window selection option is specified, the window can be interactively
selected using the cursor.
Hints: xseticon -id "$WINDOWID" path/to/icon.png Will set the icon for an xterm.
********** EDIT **********
I think you need the imagemagick program installed to access the convert command. Then, find an icon that you like and convert it to an xbm file:
Code:
convert /path/to/icon/file /path/to/xterm.xbm
Create an ~/.Xresources file with the following content:
Code:
xterm*iconPixmap: /path/to/xterm.xbm
Then merge in the ~/Xresources file:
Code:
xrdb -merge ~/.Xresources
The update came from: http://forum.xfce.org/viewtopic.php?id=6779
I finally managed to do by setting *iconHint on the xterm resource.
The value needs to be a path to an .xpm file WITHOUT the extension.
X resources that you want to be loaded at login time need to go into an ~/.Xdefaults file.
So a complete solution for an icon my-xterm.xpm would be:
mkdir ~/.icons
mv my-xterm.xpm ~/.icons/
echo 'xterm*iconHint: '$HOME'/.icons/my-xterm' >> ~/.Xdefaults
If you want your changed ~/.Xdefaults to become active without logging in, run xrdb -merge ~/.Xdefaults
If you just want one xterm to have a different icon, you can start the xterm like this:
xterm -xrm 'xterm*iconHint: /full/path/to/icon' …
Not 100% sure that changing the .desktop file would help in XFCE. But it's a worth a shot.
Find the path to your local icons, here is in the sub path of
/usr/local/share/icons.
Then simply copy the .desktop file to you home dir eg:
cp /usr/share/applications/xterm-color.desktop ~/.local/share/applications/
Then edit the .dekstop fil in an editor, there is a line like this:
Icon=xterm-color
Replace this with a icon name from your icons path and logout and back in and you should be good to go. (The icon should not have the file extention like .png or .svg).
I am using QtCreator 3.1.1 to build a cross-platform project, and so I arranged to have different compilation kits for targeting my desktop PC and my BeagleBoneBlack (BBB).
Now I would like to define some macro in qmake project file (.pro) which are specific only for a given kit.
In other words I would like do in my .pro file something like:
if(kit == BBB)
DEFINES += MY_BBB_MACRO
elseif(kit == Desktop)
DEFINES += MY_DESKTOP_MACRO
else
DEFINES += OTHER_MACRO
Is is possible? How can I do that?
I obtained some help on Qt forum (take a look here) about this problem...
Anyway the solution consists in using qmake built-in test functions.
Basically I've added some CONFIG directive in QtCreator's project management: in the following screenshot you can see for example you can see that I've added CONFIG+=BBB in the project configuration for BBB kit; in the same way I've added CONFIG+=AM335x and CONFIG+=Desktop to AM335x and Desktop kits, respectively...
Then, in my .pro file I've added something like:
and now in my source code I can use something like #ifdef PLATFORM_BBB, #ifdef PLATFORM_AM335X and #ifdef PLATFORM_DESKTOP for differentiating the program behavior depending on compilation kit.
I found another solution.
First, add additional arguments in Projects using CONFIG+=Variable name for kit.
And in .pro file, write some code like below.
Desktop {
message("Desktop is selected")
}
RPI {
message("rpi is selected")
target.path = /home/pi
INSTALLS += target
}
If you look at the general message tab, you can see that the setting works well.
I'm trying to display different language strings in my qt app by inserting each language into a QMap<QString, QString> so it can be re-used in several places and put into different combo Boxes across the application. I do this by
creating the QMap like so in the CTOR:
m_langMap.insert(QString::fromWCharArray(L"English"), "english");
m_langMap.insert(QString::fromWCharArray(L"Dansk"), "dansk");
m_langMap.insert(QString::fromWCharArray(L"Nederlands"), "dutch");
m_langMap.insert(QString::fromWCharArray(L"Čeština"), "czeck");
m_langMap.insert(QString::fromWCharArray(L"Slovenský"), "slovak");
m_langMap.insert(QString::fromWCharArray(L"Magyar"), "hungarian");
m_langMap.insert(QString::fromWCharArray(L"Român"), "romanian");
m_langMap.insert(QString::fromWCharArray(L"Latviešu"), "latvian");
m_langMap.insert(QString::fromWCharArray(L"Lietuvių"), "lithuanian");
m_langMap.insert(QString::fromWCharArray(L"Polski"), "polish");
m_langMap.insert(QString::fromWCharArray(L"Português"), "portuguese");
m_langMap.insert(QString::fromWCharArray(L"Español"), "spanish");
m_langMap.insert(QString::fromWCharArray(L"Français"), "french");
m_langMap.insert(QString::fromWCharArray(L"Italiano"), "italian");
m_langMap.insert(QString::fromWCharArray(L"Svenska"), "swedish");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"Українська"), "ukranian");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"中文"), "chinese");
m_langMap.insert(QString::fromWCharArray(L"日本語"), "japanese");
I then insert them into the combo box:
QMap<QString, QString>::const_iterator it = m_langMap.begin();
while (it != m_langMap.end())
{
ui->comboBox->addItem(it.key());
++it;
}
When the app runs, I see the following:
However, if I create a separate .ui file and insert the map the same way, I see the following (even if I include this separate Dialog class into the same application), so clearly there is no font issue as far as the App not knowing how to render the different character sets....yet I cant figure out why the first one won't render the character sets?
Can someone tell me why the first doesn't work but the second does? I checked the Designer and its Locale is set to 'C, Default' in both ui files I've shown below. I can't seem to figure out what else is causing the difference for the first not to work, and the second does work within the same application.
Thanks for any help!
The other test Dialog:
Your code is correct, but the problem is that your source file cannot contain Unicode characters - apparently it is using different coding.
Save file as UTF-8 and everything should work!
In the first screenshot the font used by the combobox is much larger than in the second screenshot. My guess is that you have changed the font either in the GUI designer or in the code and the second (working) screenshot is using the default font. It might be that when you have changed the font size, you have also changed the font to something that doesn't contain all the required Unicode characters. Try changing the font used by the combobox to something else.