Need help transitioning from Qt to Wx

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
GeatMaster
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jan 31, 2017 6:54 pm

Need help transitioning from Qt to Wx

Post by GeatMaster » Tue Jan 31, 2017 8:27 pm

Hello,

I'm trying to convert an application I've written from Qt to Wx for licensing reasons, luckily I thought this might happen and barely integrated the GUI at all, in favor of a C adapter; however even then I'm having problems. So I'm having trouble figuring out how to do things in Wx that I could do with Qt.

In Qt I had a QHorizontalSizer with a check box, a spacer, and a button, the effect was that the check box was left aligned and the button was right aligned. When I tried this in Wx the result was that each item in the sizer took up 1/3 of the space, which is not at all what I want. Even with the button set to not expand and as being right aligned, each item seems to want to be the same size. Next I tried it with a flexgrid sizer using only 1 row, and now the sizer took up no space at all. So now I am at a loss.

How do i render to an OpenGl canvas from a secondary thread? Do I just create the GL context in the second thread and render normally ending with wx's SwapBuffers()? if so is SwapBuffers a blocking operation when vsync is on?

Is there an equivalent of QPainter? I saw that wxCanvas seems to be that but isn't maintained anymore, and was superseded by wxArt2D most of which seems to be abandoned, e.g. the examples page has no images, the source tab of the soureforge page is empty, etc. Or is there an external library that can create pixel data that wxImage can make use of or something? I'm trying to render some graphs, and I don't want to use GL because switching GL contexts is a lot of overhead.

When working in Qt I had this:

Code: Select all

int main(int argc, char * argv[])
{
	Engine::InitializeThreads(getLanguageCode(QLocale()));
	
	QApplication a(argc, argv);
	MainWindow w;
	
	Engine::SynchronizeThreads();
	w.show();
	int i = a.exec();
	
	Engine::JoinThreads();
	return i;
}
But I can't even find where the main() function even is in Wx, so I'm at a loss in adapting that bit of code.

Thanks for any help!

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Need help transitioning from Qt to Wx

Post by doublemax » Tue Jan 31, 2017 9:11 pm

In Qt I had a QHorizontalSizer with a check box, a spacer, and a button, the effect was that the check box was left aligned and the button was right aligned. When I tried this in Wx the result was that each item in the sizer took up 1/3 of the space, which is not at all what I want.
Use a horizontal wxBoxSizer, add wxCheckBox with proportion = 0, AddStretchSpacer( propotion=1), add wxButton (propotion = 0). As the stretchspacer is the only element with proportion > 0, it will "consume" all additional space available.
How do i render to an OpenGl canvas from a secondary thread? Do I just create the GL context in the second thread and render normally ending with wx's SwapBuffers()? if so is SwapBuffers a blocking operation when vsync is on?
I don't know about this, i'm not even sure it's possible at all, as wxWidgets requires all GUI operations to happen in the main thread.
Is there an equivalent of QPainter?
Without knowing what it does, i can't tell. If you want to draw into a bitmap, you can use a wxMemoryDC and use "normal" wxDC or wxGraphicsContext methods.
But I can't even find where the main() function even is in Wx, so I'm at a loss in adapting that bit of code.
There is no main, or to be exact, it's hidden inside the IMPLEMENT_APP() macro. Check the "minimal" sample that comes with wxWidgets to see the basic architecture of a wxWidget application in action. The code you have in main will usually go into MyApp::OnInit() (MyApp = your class deriving from wxApp through the IMPLEMENT_APP() macro).
Use the source, Luke!

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 695
Joined: Mon Apr 30, 2012 11:07 pm

Re: Need help transitioning from Qt to Wx

Post by Manolo » Tue Jan 31, 2017 11:29 pm

How do i render to an OpenGl canvas from a secondary thread? Do I just create the GL context in the second thread and render normally ending with wx's SwapBuffers()? if so is SwapBuffers a blocking operation when vsync is on?
Rendering simultaneously from two threads is not a good idea. Better you render in one thread while updating data from the other thread. For this you need a shared context at wxGLContext creation (see docs http://docs.wxwidgets.org/trunk/classwx ... ntext.html).
Don't forget that before sending any GL commands the GL context must be set before, by using SetCurrent() (again, docs).

Additional info OGL with multithreading: https://www.khronos.org/opengl/wiki/Ope ... ithreading

GeatMaster
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jan 31, 2017 6:54 pm

Re: Need help transitioning from Qt to Wx

Post by GeatMaster » Wed Feb 01, 2017 1:49 pm

Thank you!

QPainter is a software renderer that can render simple 2D shapes like lines and boxes as well as text. It also allows multiple rendering contexts without the slowdown of GL context switches. It's not that hard to manually make one that does the lines and boxes, but I don't know how to add text.

GeatMaster
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jan 31, 2017 6:54 pm

Re: Need help transitioning from Qt to Wx

Post by GeatMaster » Wed Feb 01, 2017 1:54 pm

doublemax wrote:
Is there an equivalent of QPainter?
Without knowing what it does, i can't tell. If you want to draw into a bitmap, you can use a wxMemoryDC and use "normal" wxDC or wxGraphicsContext methods.
wxGraphicsContext was the equivalent, thank you!

Post Reply