Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:13:51+00:00 2026-05-31T13:13:51+00:00

I have a QComboBox so the user can a network name from from a

  • 0

I have a QComboBox so the user can a network name from from a model column. I’m using code like this:

self.networkSelectionCombo = QtGui.QComboBox()
self.networkSelectionCombo.setModel(self.model.worldLinks)
self.networkSelectionCombo.setModelColumn(WLM.NET_NAME)

I’m using PySide, but this is realy a Qt question. Answers using C++ are fine.

I need to give the user the option of not selecting any network. What I’d like to do is add an extra item to the combo box called ‘None’. However this will just get overridden by the model contents.

The only way I can think of is to create an intermediate custom view on this model column and use that to update the combo, then the view can handle adding in the extra ‘magic’ item. Does anyone know a more elegant way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:13:52+00:00Added an answer on May 31, 2026 at 1:13 pm

    One possible solution is to subclass the model you are using in order to add there the extra item. The implementation is straight forward. If you call your model MyModel then the subclass would look like this (C++ used):

    class MyModelWithNoneEntry : public MyModel
    {
    public:
        int rowCount() {return MyModel::rowCount()+1;}
        int columnCount() {return MyModel::columnCOunt();}
        QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const
        {
            if (index.row() == 0)
            {
                 // if we are at the desired column return the None item
                 if (index.column() ==  NET_NAME && role == Qt::DisplayRole)
                      return QVariant("None");
                 // otherwise a non valid QVariant
                 else
                      return QVariant();
            }
            // Return the parent's data
            else
                return MyModel::data(createIndex(index.row()-1,index.col()), role);       
        } 
    
        // parent and index should be defined as well but their implementation is straight
        // forward
    } 
    

    Now you can set this model to the combo box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Combobox where user can choose an icon. I'd like the dropdown
This question relates to this question . I have a EF model like this
I have form with user defined filters ( combobox with column names, combobox with
I have a ComboBox that I set up like this: this.cmbCustomerJob.DisplayMember = display; this.cmbCustomerJob.AutoCompleteMode
I have XAML similar to this: <ListBox ItemsSource={Binding SearchCriteria, Source={StaticResource model}} SelectionChanged=cboSearchCriterionType_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>
I would like to have a textbox in a Silverlight app where the user
I'm making a text editor using Text Area. Which user can change font size,
I have a datagridview which I'm using for data entry. I've done this before
Here's the situation: i have a SearchPage where an user can make a complex
I have a combobox and it's editable. So the user can select an item,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.