Results 1 to 6 of 6

Thread: How do I add a toolbar to a tab in design mode?

  1. #1
    Join Date
    Dec 2016
    Posts
    15
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How do I add a toolbar to a tab in design mode?

    Hello,

    This is my first time using QT, and I have been playing around in the QT creator's Qt widget application. I'm trying to see how to accomplish these tasks:

    1. I am currently trying to add a toolbar within a tab, instead of the Main Window, directly in the designer. I tried editing the ui file (by opening it in plain text, modifying, and then rebuilding, but ended up with too many errors.) I'm curious to know how I can do this?

    2. Also, I have menu items in a menu, and I want to add a new tab with respect to every menu item, as the user clicks on the menu.
    Is there an example that could point me to implementing the same?

    3. Does Qtablewidget support excel filter based column filtering, and drag and drop grouping by columns?

    Thanks!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do I add a toolbar to a tab in design mode?

    I am currently trying to add a toolbar within a tab
    Are you talking about replacing or adding to the text and icon that appear at the top of the tab? That would be a rather strange design. It probably would not be easy to achieve. QTabWidget / QTabBar have prescribed appearance and behavior in response to keyboard and mouse actions. In order to implement a toolbar, you would have to override this behavior so that clicks on your toolbar items could be detected and handled. You'd probably also have to reimplement the QTabBar::paintEvent() to draw your tool bar in addition to the text, as well as handle the resize and layout issues. None of this will be easy to do or to debug.

    If that's not what you mean, then you'll have to explain more and maybe draw a picture.

    I want to add a new tab with respect to every menu item, as the user clicks on the menu.
    Connect a slot to the QMenu::triggered() signal for each top-level QMenu you add to your QMenuBar. Create your tab in the slot. Of course, you probably want to ensure that the user doesn't create a new tab every time the same menu item is clicked if a tab has already been created for it.

    excel filter based column filtering
    What's "excel filter based column filtering"? QTableWidget isn't Excel; it is a generic widget for displaying tables. If you mean, can you show / hide columns based on some external criterion, yes, through QTableView::setColumnHidden().

    drag and drop grouping by columns
    You mean drag and drop to rearrange columns? Yes, through QHeaderView::setSectionsMovable() and QTableView::horizontalHeader().

    If you want to implement a lot of custom functionality or filter rows based on more complex logic, then you would be better off going to the Model / View architecture and implementing a custom QAbstractItemModel and using QTableView in conjunction with QAbstractProxyModel / QSortFilterProxyModel.
    Last edited by d_stranz; 6th December 2016 at 23:51.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Dec 2016
    Posts
    15
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a toolbar to a tab in design mode?

    Thank you for your response.

    1. https://www.ischool.utexas.edu/techn...on_PC01_lg.jpg

    I am trying to create a 'qtoolbar' within a 'Qtabwidget'. The Qtabwidget is within the main window. Currently, I can add a toolbar only at the qmainwindow level, upon selecting 'add toolbar' in the context menu of QMainWindow. I am not able to add the toolbar to a tabwidget, as it seems to only be a property of the qmainwindow. In that case, I do not know if there is a way to embed another qmainwindow inside the tab itself and have it's toolbar show. I understand that there would be a way to do it in a programmatic way, but I was wondering about how to go about this.

    2. Thank you, I was able to implement the tab creation on menu item click.

    3. http://www.jkp-ads.com/images/ExcelTable06.gif

    I am trying to see if there is an inbuilt way to create the same filter as above. A list of values unique to a column and a checkboxes to filter the items based on this.

    4. https://documentation.devexpress.com...nt=img2727.jpg

    By Grouping, I mean something equivalent to the above image.

    Thanks

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do I add a toolbar to a tab in design mode?

    I am trying to create a 'qtoolbar' within a 'Qtabwidget'. The Qtabwidget is within the main window.
    1 - Ah, this is a Microsoft "ribbon bar." It's really a menu where the menu items are represented as groups of icons that appear below it. There is a commercial product called "QtitanRibbon" that does this. I don't know if that is an option for your project. There is also a QRibbon project on SourceForge which has been inactive since 2014.

    If you want to implement something like this yourself, I think I would start by using QDockWidget as a container for a QTabWidget. The widget contained on each tab would contain the buttons and groups for the commands for that tab. This is not an easy project.

    3 - Wow, you set high bars for yourself. Basically, you would use QTableWidget::setCellWidget() to set a QComboBox in the cell. I have no idea how you would insert a combo box into the popup as your example shows. I think ultimately you will need to design a custom combobox widget for this and use it as the cell widget.

    4 - This isn't available in QTableView / QTableWidget. You might be able to use QTreeView / QTreeWidget for this, but tree views don't draw grid lines. Maybe something like CuteReport can do this.

    If you are developing this GUI as part of a project and not for homework, there are a lot of resources out there, both commercial and open-source. Using / adapting some of these might save you a lot of work. Look at the inqlude site or under the "Qt Programs" topic on linux-apps.com.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Dec 2016
    Posts
    15
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a toolbar to a tab in design mode?

    Thank you very much for your response, I really appreciate your help! Yes, this was actually for a project at work. ^^;

    I have yet another question on QTableView.

    We have a requirement where in our datasource for the qtableview comes from the server in the form of a json.
    Could you please point me to an existing example which implements the above functionality?
    I have already looked at jsonlistmodel(for qml) and save game example, but I'm not able to figure out how to implement the same (and feed data in a json format to the tableview) for a qt widgets application in c++.

    Is there a way to implement the jsonlistmodel in c++? (someway I can specify the url directly, obtain the json object and pass it as a parameter to the table?)

    Thank you again!

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a toolbar to a tab in design mode?

    You could parse the JSON data using Qt's JSON classes, e.g. see QJsonDocument, and then either feeding the data into a custom model, derived from QAbstractTableModel, or adding it to a QStandardItemModel.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 28th June 2015, 09:51
  2. Replies: 1
    Last Post: 23rd April 2014, 10:03
  3. Replies: 0
    Last Post: 28th October 2010, 13:24
  4. Replies: 5
    Last Post: 11th September 2010, 14:29
  5. Replies: 3
    Last Post: 5th October 2008, 23:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.