Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to enhance Qt's QPrintPreviewWidget by allowing it to display page numbers (in the footer somewhere). Unfortunately, I can't quite figure out how to go about it without hacking up Qt's source. I see a great spot for this additional code (in qpaintengine_preview.cpp, in newPage() method) but that means I'm going to have to recompile the whole of Qt (I got a binary build from Trolltech). Furthermore, if I decide to run an app that uses this functionality on someone else's box, I'm going to have to recompile there as well (say if it's a different arch).
Are there any other cleaner ways?
Thanks
Is the newPage() method virtual? If so, you could subclass and use that in you own applications, which would be a bit easier.
The second option would be to statically link your executable with the modified Qt libraries. You need to be aware of licensing concerns to do this. This way, every place you put the app will have your modified functionality. (You would still need to recompile for different architectures.)
Finally, you could get the latest sources from http://qt.gitorious.org/, modify them in the way you desire, and submit a patch back to the trolls. If you do this, you'll probably have to keep the old behavior the default, and add an option to enable the new behavior. They may or may not accept the patch. And if they do accept the patch, you may not be able to rely on other people's computers getting that version for quite some time, if ever.
Read the source code.
In this case, read QPrintPreviewDialog source code to see how it does it. This standard dialog has navigation buttons and a current page display, so it kind of does what you want (that is, if I really understood what you want to accomplish). The methods you're looking for are the following (src/gui/dialogs/qprintpreviewdialog.cpp):
void QPrintPreviewDialogPrivate::_q_previewChanged()
void QPrintPreviewDialogPrivate::_q_navigate(QAction* action)
void QPrintPreviewDialogPrivate::updateNavActions()
Basically, _q_previewChanged() is connected to QPrintPreviewWidget::previewChanged() signal. When it is emitted, the page number is updated with information acquired from QPrintPreviewWidget::currentPage() and QPrintPreviewWidget::pageCount().
As for extending the behavior of QPrintPreviewWidget you can try two approaches, both of them do not require a tailored version of Qt:
Extend QPrintPreviewWidget
In the constructor, access the layout() (it is a QVBoxLayout that is used interanally), add the footer widget, connect the previewChanged() signal to a slot that updates the page number and be done. The problem with this approach is that it counts on the layout to be present and be a QVBoxLayout. Since this is somehow private, it can break with newer versions.
Create a new class extending QWidget or QFrame
If you don't require your widget to be a QPrintPreviewWidget, just create a new QWidget derived class and add the print preview widget and the footer to a layout, connects slots etc. Use your derived widget instead of QPrintPreviewWidget.
Now, if you want to modify the behavior of the widget on already deployed binaries, things get uglier. I cannot help in this case.
If you have a library and this library has same symbols linker at runtime is looking for - to get the code for the print preview - then you can inject your own code to replace the real implementation. Method is called dll injection.
Check http://en.wikipedia.org/wiki/DLL_injection for more info
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
I've been experimenting with using HTML as a structure for generating a help information area for a desktop program that I've finished writing and that seems to work ok, though I don't really like the way it is turning out and I began to wonder if perhaps there might be a better way to go about it. Perhaps a library that makes generating and linking content within Java a little easier in that context or some other means that I'm not aware of.
I did some Googling on the topic but found nothing specifically in reference to help menu / content creation.
Does anyone know of any libraries out there that would make it easier to create help info for end users?
Or, is there a "best practice" for doing this or any other method to that end?
Thank you,
Mike
What does Idea do?
Intellij is large java app that has decent help documentation. You could look and see how they did that, if that is something you wish to emulate. I think it is mostly good quality writing and organization rather than tool support, though I guess they use decent tooling too.
I did a quick check to see how idea create their doc. They write in markdown format. Here is the markdown style guide they use for creating the document, in generated html form and in markdown authoring form. A repository of docs used for one of their products is their open source sdk docs. The SDK docs project is an Idea project, so I guess they just use Idea for authoring. If it seems to be something that would help you, you could try cloning the project and generating documentation from it or contacting the project contributors for more info.
As far as tying the help content into your app, either you can display it in situ using a WebView or link to it externally using HostServices. You could study the help system used within Idea to see how they generally do that, e.g. help menus used, key commands responded to, icons used to link to the help system, etc.
Generally, the way it works is:
The document is written in markdown then processed and rendered to html.
The html documents have copious anchors throughout.
The help menu items link to the anchors directly.
Help menus and shortcut keys follow platform specific conventions and differ between Windows and Mac.
There is a single ? icon in dialogs which appears in a consistent place and it links to an anchor in the html for context sensitive help in the dialog.
The documentation itself is hosted on a website so it can be accessed independently of the application.
The app launches an external browser to view the help rather than using something like a WebView to show the help internally.
Additionally, Idea will use tooltips which show up on hover. Tooltips aren't used for every control or UI element, only certain ones. If there is a keyboard accelerator which can be used to trigger the control action, then there is a tooltip for it, and in the tooltip it lets you know what the keyboard shortcut to trigger it is.
The rendered HTML to which the app is linked is hosted at the jetbrains website.
Linking to HTML help
You could:
Link to your own hosted website, OR
Link to html files packaged with your app.
Both could be rendered by either WebView or a browser showing a document using HostServices, using the file: protocol to access html files packaged with your app or https: protocol for files hosted on your web server.
What does SceneBuilder do?
For a pure JavaFX application, SceneBuilder is quite large and complex. It has no reliance on internal help at all, just a single help menu item, accessible via an F1 shortcut. The help links to a website authored and hosted by Oracle (using the standard tool Oracle use for authoring most Java platform docs, which is likely a commercial tool). It is not as nicely integrated and context sensitive as the Idea example but it does demonstrate a simple approach to documenting an app via an external website.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am very new to this, it's my first GUI project. I want to create a GUI in Qt that has multiple windows in which I have buttons that take me from a window to another. Also, across these windows, I will be passing data.
I am using Qt Designer, and I was wondering what would be the best way to do this. Do I create multiple Main Windows for example? Or should they be as Widgets? Or some other way?
Any help would be appreciated.
The main window is one by definition. If you need to create multiple windows however the simplest thing to do is to create a new widget without any parent and show it with show().
QWidget *fstWin = new QWidget(nullptr);
QWidget *scdWin = new QWidget(nullptr);
fstWin->show();
scdWin->show();
https://doc.qt.io/qt-5/application-windows.html
Your question is very basic. Seems you started to learn GUI from the beginning and probably the programming at all.
Anyway, you dont need more than one Main Window. This is where your program starts.
All other windows must be created from the designer. They are Dialogs. To add a new Dialog, you need to click on your project (right pane), and select Add New...
From the dialog, just select QT and then Qt Designer Form Class. Follow the Wizard and set the type and name of the dialog.
Finishing the Wizard, will add you three items in the project with the name you selected: Header File, Source file (.cpp) and Form file (.ui).
To show a the newly created form, you need to #include your .h file in the mainwindow.h then you need to create a member variable of type "your newly created class" in MainWindow class.
To show the new dialog, just use the function .show() from the member variable. To show the dialog in modal state, use the .exec() function of the member variable.
To pass data between windows, you need to make corresponding methods in your newly created class.
But, just before doing all this stuff, I advise you to take some lessons about Object Oriented Programming. You have to know, what is Class, Object, Member and Field/Variable
Or it will be very hard for you learn more.
We need a tree view with File system and check boxes in QT. Is there any way to achieve that?
The tree we need would look something like below:
UPDATE:
I am able to achieve it with subclass of QFileSystemModel. Still have few challenges, but at least subclass is working. Below is the code if anyone needs it. Below is the link to the code -
https://drive.google.com/file/d/1qViZ3iEW2pV2th0jQhzneDL14SEhIgS0/view?usp=sharing
The pending work is to apply a wait cursor (or make treeview uneditable when the check/uncheck is taking place).
PS: It will take a lot of time if root node is checked.
Well, all of that can be achieved with minimal customizations of built-in classes, actually those checkboxes is almost the only thing that has to be done yourself.
QFileSystemModel already provides a proper model for displaying the current filesystem contents, it can be subclassed
As for QML, the best demo is already provided by Qt, check the File System Browser Example. This example uses some deprecaded Qt functionality, but still it shows the basic concept.
The modern techniqes can be also found in the answers to the following question: Qt File Browser based on QML
Hopefully, all that helps you, good luck!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
in my Qt application I'd like to output PDF-reports. The reports should be slightly modifiable for a particular customer. My idea was to create PFDs using QPrinter from rendered QWebkit-view. Rendered QML could also work. Looks for me as a very easy was to create PDF-reports with very flexible layout customization (CSS/HTML or QML) and without the need to learn/introduce additional software-package into the project.
Is someone aware of such an implementation already? It should be Open-Source (free or commercial)?
My wish-list is :-)
It should be able to display images preferably provided from
client-application as QImage/QPixmal.
It should be able either to
accept all variables as QMap or query values from a Postgres DB.
It should be either embeddable as code or linked as a library
EDIT
already checked:
QtRPT - pretty experimental and unmature. Many magics, comments in Russian in code.
NCReport - Open-source code is too old, last update 2007. Doesn't compile with Qt4.8.4. New versions are provided under commercial licenses. Commercial version looks very mature, has good documentation (ca. 100p), However I'm looking for a software which renders html/QML, so we could order a HTML-developer for creating/maintaining reports.
I dont think there is something ready made exists, otherwise it would be well known, because an issue itself pretty common. As a previous answer I also wrote my own generator. It's not open source, thought.
Problem is not only in printing (as being mentioned in previous answer). It can be more or less solved as soon as you can split whole report into pages yourself. Then you can render report content with headers/footers/page numbers/etc on 'per page' basis and print them separately.
Main problem is that it's easier up to me (having in mind all options Qt provides) to develop nice report generator for particular software, rather then trying to develop something very generic. In this case you have to either limit yourself on features you can use in the report OR introduce a lot of 'magics', certain assumptions/conventions etc.
You can make some kind of generic code for some cases then your reports all have similar structure (for example - header - first page header - main table section- footer with page numbering and all other pages the same without first page header), and then it's fairly simple to make an algorithm which will nicely split you main table section into pages.. but it's all gone as soon as you start think about more complicated scenarios with graphs etc.
An engine I've done based on JS and operates using basic reports primitives (like table, graph, label) which have some layout properties and actually JS code places them on a final report. Some reports primitives can be automatically splitter between pages some not..
I have made that kind of report generator using QWebKit (Qt version 5.1). It is not open source, though.
The biggest problem is that WebKit (or any browser's layout engine that I tried) does not work very well with printing. CSS standard covers printing, but the layout engines do not implement that stuff, or implement it only partially. So if you want features like headers and footers, page numbers, support for multiple paper sizes and support for both landscape and portrait, you have to do a lot of googling and testing. Almost nothing works as expected, so workarounds need to be invented and ugly hardcoding done.
So you can make a report generator using QWebKit. It's not going to be fun and new versions of Qt and QWebKit will most probably break something. So I would recommend making the report generator a separate application so that you can use different Qt versions for the main application and the report generator. At least design the report generator so, that you can separate it from the main application later if needed.
Im just pondering best practice with an application I'm developing. Its a simple one window application using qt creator. It's just going to start a QProcess and show the output in a QTextEdit box. To do this there needs to be a bit of processing between the output of the QProcess and the QTextEdit but i dont know where i should do this, should i create a new class to do that or add member functions and extra signals and slots to my main window? I dont want mainwindow to become bloated and hard to read but equally i dont want to have more source files than really I need.
Any thoughts?
The main window class can very easily get bloated with all kinds of functionality. I've dealt with that myself, so it's a very real trouble.
Really, though, this is not so much of QT question as it is an object-oriented design question. The key is that your output window does not need to be a part of QMainWindow, so it probably shouldn't be. Make the display a widget, and insert it onto the main window. That is much more flexible, as if you ever need to move that output pane for any reason, it won't be coupled to a specific part of the program.
The logic that feeds data into that output pane should also get its own class, separating the responsibility for displaying the output from the responsibility for acquiring the output.
For reference on the concepts behind my suggestion, see the Single Responsibility Principle and the separation of concerns.
Also - you may wish to have a read at this link to model view delegate information which is how I tend to develop in Qt. Like the person above says - this is more a question of good OO design.